Product SiteDocumentation Site

6.3. OProfile

OProfile is a system-wide Linux profiler, capable of running at low overhead. It consists of a kernel driver and a daemon for collecting raw sample data, along with a suite of tools for parsing that data into meaningful information. OProfile is generally used by developers to determine which sections of code consume the most amount of CPU time, and why.
During a profile run, OProfile uses the processor's performance monitoring hardware. Valgrind rewrites the binary of an application, and in turn instruments it. OProfile, on the other hand,simply profiles a running application as-is. It sets up the performance monitoring hardware to take a sample every x number of events (e.g. cache misses or branch instructions). Each sample also contains information on where it occurred in the program.
OProfile's profiling methods consume less resources than Valgrind. However, OProfile requires root privileges. OProfile is useful for finding "hot-spots" in code, and looking for their causes (e.g. poor cache performance, branch mispredictions).
Using OProfile involves starting the OProfile daemon (oprofiled), running the program to be profiled, collecting the system profile data, and parsing it into a more understandable format. OProfile provides several tools for every step of this process.

6.3.1. OProfile Tools

The most useful OProfile commands include the following:
opcontrol
This tool is used to start/stop the OProfile daemon and configure a profile session.
opreport
The opreport command outputs binary image summaries, or per-symbol data, from OProfile profiling sessions.
opannotate
The opannotate command outputs annotated source and/or assembly from the profile data of an OProfile session.
oparchive
The oparchive command generates a directory populated with executable, debug, and OProfile sample files. This directory can be moved to another machine (via tar), where it can be analyzed offline.
opgprof
Like opreport, the opgprof command outputs profile data for a given binary image from an OProfile session. The output of opgprof is in gprof format.
For a complete list of OProfile commands, refer to man oprofile. For detailed information on each OProfile command, refer to its corresponding man page. Refer to Section 6.3.4, “OProfile Documentation” for other available documentation on OProfile.