Using Linux's Perf For Providing More Automated Performance Counter Metrics
Written by Michael Larabel in Software on 13 October 2015. Page 1 of 1. 6 Comments

A Phoronix reader recently asked about adding perf profiling to PTS for helping to better identify performance problems within the Linux kernel. As it was easy to do and further shows how easy and extensible the Phoronix Test Suite can be, I added such a module today. Here's some more details on how -- whenever running any benchmark -- via the Phoronix Test Suite you can very trivially expose all of the performance event counts on a universal per-test basis.

For those unfamiliar with the Linux kernel's perf subsystem and user-space "perf" command, see the Wikipedia article or Perf on the Linux Kernel Wiki. Long story short, perf is for Linux profiling with performance counters.

I committed to Phoronix-Test-Suite on GitHub very basic initial support that will automatically run "perf stat" on any binary being run for Phoronix Test Suite benchmarking. Afterwards, it reports various event counter metrics back into the Phoronix Test Suite that are then rendered as extra graphs on the benchmark result files.

Here's an example and shows an MP3 encoding benchmark run followed by Perf's reported task clock, number of context switches, page faults, branches, and branch misses. Other perf output reporting could be trivially adopted.

This Linux perf support was implemented in just a few dozen lines of code. It's implemented as a Phoronix Test Suite module that automatically loads whenever LINUX_PERF=1 environment variable is set. Assuming you're running the Phoronix Test Suite on Linux and have the "perf" utility installed already, this module will then make use of perf reporting whenever benchmarks are run and the perf output data is automatically appended to the result file XML -- it works automatically for the hundreds of test profiles available.

Here's another example showing the basic perf data so far exposed or over here with multiple Stream runs. Thanks to the extensible Phoronix Test Suite architecture, this module should work with any Phoronix Test Suite test profile out there and goes to show just how adaptable PTS can be for open-source benchmarking. This module is also quite similar to the performance per dollar benchmarking module. It's also just like the system_monitor module activated via MONITOR=all for monitoring various system hardware/software sensors while running Phoronix Test Suite tests, such as to monitor the CPU temperature or core usage or system performance-per-Watt / power usage monitoring. Plugging into the Phoronix Test Suite, it will work fine when merging multiple results together, using PTS auto-bisecting, and the other many capabilities of our open-source benchmarking software.

Anyhow, try it out in Phoronix Test Suite Git and share what you think by just setting the LINUX_PERF=1 environment variable if having the perf user-space utility installed. This perf reporting can be extended much further to be more useful to developers in narrowing down performance changes, so if you're so inclined, go checkout the simple code addition as contributions are certainly welcome for our GPL benchmarking framework. Or if you're not able to contribute code directly, we are always happy to engage in custom engineering engagements and other commercial services to support the Phoronix Test Suite / / Phoromatic within organizations or even straightforward sponsorship to further enhance the open-source components to the Phoronix Test Suite. Individuals can help out by simply being Phoronix Premium subscribers to support our testing efforts.

If you enjoyed this article consider joining Phoronix Premium to view this site ad-free, multi-page articles on a single page, and other benefits. PayPal tips are also graciously accepted. Thanks for your support.

Related Articles
About The Author
Author picture

Michael Larabel is the principal author of and founded the site in 2004 with a focus on enriching the Linux hardware experience. Michael has written more than 20,000 articles covering the state of Linux hardware support, Linux performance, graphics drivers, and other topics. Michael is also the lead developer of the Phoronix Test Suite, Phoromatic, and automated benchmarking software. He can be followed via Twitter or contacted via

Trending Linux News