Measuring performance with the perf kernel tool
top on Steroids
You can create a performance counter profile in real time with perf top
(Figure 1). The overview is similar to that of top
, but you can jump directly to the individual events.
perf stat
counts the events of the entire system until you abort by pressing Ctrl+C, or the specified command terminates. Listing 3 shows the subcommand in action; it lists two events for the factor
command.
Listing 3
Output from perf stat
01 $ sudo perf stat -e branches -e branch-misses factor 120808125801214124898080833 02 120808125801214124898080833: 13 29 911 7589 21089 77471 28369829 03 04 Performance counter stats for 'factor 120808125801214124898080833': 05 06 191,242 branches 07 10,332 branch-misses # 5.40% of all branches 08 09 0.000649438 seconds time elapsed 10 11 0.000699000 seconds user 12 0.000000000000 seconds sys
Data Recorder
The perf
record
command can generate a performance counter profile for a specific command. If you want an overview of the entire system, or if the process to be examined is unknown, simply add the sleep
command:
sudo perf record -ag sleep 5
This line creates the default perf.data
file in the current directory. The -a
switch ensures that perf
considers all CPUs, and -g
generates a call graph. -i
lets you feed a file to perf record
.
The perf report
command evaluates the stored data and uses the perf.data
file. As with perf top
, the command presents an overview. After pressing Enter, you also see details for the functions.
By the way, the --sort= comm,dso
switch (see Figure 1) provides a better overview. Figure 2 shows the output for an Intel Kaby Lake system with Gnome 3.30.1 playing a movie in Firefox 63.0.3. The figure shows that the CPU and not the GPU is used for decoding.
Event-Driven
If only certain events are of interest, the -e
switch can help. Listing 4 shows the output on a system with Rsync running.
Listing 4
Track Events
01 $ sudo perf report --stdio 02 [...] 03 # Samples: 1K of event 'block:block_rq_issue' 04 # Event count (approx.): 1741 05 # 06 # Children Self Command Shared Object Symbol 07 # ........ .... ........... ................ .................... 08 # 09 93.74% 93.74% rsync kernel.kallsyms] [k] blk_peek_request 10 | 11 |--89.20%-- __lxstat64 12 | blk_peek_request 13 | 14 |--3.45%-- __GI___mkdir 15 | blk_peek_request 16 | 17 |--0.63%-- 0x646c6975622f3930 18 | __GI___link 19 | blk_peek_request 20 | 21 -0.46%-- 0x6d492f636f642f65 22 __GI___link 23 blk_peek_request 24 25 89.20% 0.00% rsync libc-2.27.so [.] __lxstat64 26 | 27 ---__lxstat64 28 blk_peek_request 29 [...]
--stdio
tells perf
to display the overview in plain text directly on the console. The recorded event was a request to the kernel block layer. The command line was:
sudo perf record -e block:block_rq_issue -ag
« Previous 1 2 3 4 Next »
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Gnome 48 Debuts New Audio Player
To date, the audio player found within the Gnome desktop has been meh at best, but with the upcoming release that all changes.
-
Plasma 6.3 Ready for Public Beta Testing
Plasma 6.3 will ship with KDE Gear 24.12.1 and KDE Frameworks 6.10, along with some new and exciting features.
-
Budgie 10.10 Scheduled for Q1 2025 with a Surprising Desktop Update
If Budgie is your desktop environment of choice, 2025 is going to be a great year for you.
-
Firefox 134 Offers Improvements for Linux Version
Fans of Linux and Firefox rejoice, as there's a new version available that includes some handy updates.
-
Serpent OS Arrives with a New Alpha Release
After months of silence, Ikey Doherty has released a new alpha for his Serpent OS.
-
HashiCorp Cofounder Unveils Ghostty, a Linux Terminal App
Ghostty is a new Linux terminal app that's fast, feature-rich, and offers a platform-native GUI while remaining cross-platform.
-
Fedora Asahi Remix 41 Available for Apple Silicon
If you have an Apple Silicon Mac and you're hoping to install Fedora, you're in luck because the latest release supports the M1 and M2 chips.
-
Systemd Fixes Bug While Facing New Challenger in GNU Shepherd
The systemd developers have fixed a really nasty bug amid the release of the new GNU Shepherd init system.
-
AlmaLinux 10.0 Beta Released
The AlmaLinux OS Foundation has announced the availability of AlmaLinux 10.0 Beta ("Purple Lion") for all supported devices with significant changes.
-
Gnome 47.2 Now Available
Gnome 47.2 is now available for general use but don't expect much in the way of newness, as this is all about improvements and bug fixes.