English
OProfile
indexterm:[system analysis,OProfile,OProfile]indexterm:[OProfile] OProfile is a low overhead, system-wide performance monitoring tool. It uses the performance monitoring hardware on the processor to retrieve information about the kernel and executables on the system, such as when memory is referenced, the number of L2 cache requests, and the number of hardware interrupts received. On a {MAJOROS} system, the `oprofile` package must be installed to use this tool.
Many processors include dedicated performance monitoring hardware. This hardware makes it possible to detect when certain events happen (such as the requested data not being in cache). The hardware normally takes the form of one or more _counters_ that are incremented each time an event takes place. When the counter value increments, an interrupt is generated, making it possible to control the amount of detail (and therefore, overhead) produced by performance monitoring.
OProfile uses this hardware (or a timer-based substitute in cases where performance monitoring hardware is not present) to collect _samples_ of performance-related data each time a counter generates an interrupt. These samples are periodically written out to disk; later, the data contained in these samples can then be used to generate reports on system-level and application-level performance.
Be aware of the following limitations when using OProfile:
*Use of shared libraries* — Samples for code in shared libraries are not attributed to the particular application unless the [option]`--separate=library` option is used.
*Performance monitoring samples are inexact* — When a performance monitoring register triggers a sample, the interrupt handling is not precise like a divide by zero exception. Due to the out-of-order execution of instructions by the processor, the sample may be recorded on a nearby instruction.
*pass:attributes[{blank}][command]#opreport# does not associate samples for inline functions properly* — [command]#opreport# uses a simple address range mechanism to determine which function an address is in. Inline function samples are not attributed to the inline function but rather to the function the inline function was inserted into.
*OProfile accumulates data from multiple runs* — OProfile is a system-wide profiler and expects processes to start up and shut down multiple times. Thus, samples from multiple runs accumulate. Use the command [command]#opcontrol --reset# to clear out the samples from previous runs.
*Hardware performance counters do not work on guest virtual machines* — Because the hardware performance counters are not available on virtual systems, you need to use the `timer` mode. Enter the command [command]#opcontrol --deinit#, and then execute [command]#modprobe oprofile timer=1# to enable the `timer` mode.
*Non-CPU-limited performance problems* — OProfile is oriented to finding problems with CPU-limited processes. OProfile does not identify processes that are asleep because they are waiting on locks or for some other event to occur (for example an I/O device to finish an operation).
Overview of Tools
indexterm:[OProfile,overview of tools] xref:OProfile.adoc#tb-oprofile-tools[OProfile Commands] provides a brief overview of the most commonly used tools provided with the `oprofile` package.
OProfile Commands
|Command|Description
|[command]#ophelp#|Displays available events for the system's processor along with a brief description of each.
|[command]#opimport#|Converts sample database files from a foreign binary format to the native format for the system. Only use this option when analyzing a sample database from a different architecture.
|[command]#opannotate#|Creates annotated source for an executable if the application was compiled with debugging symbols. See xref:OProfile.adoc#s2-oprofile-reading-opannotate[Using [command]#opannotate#] for details.
|[command]#opcontrol#|Configures what data is collected. See xref:OProfile.adoc#s1-oprofile-configuring[Configuring OProfile Using Legacy Mode] for details.
|[command]#operf#|Recommended tool to be used in place of [command]#opcontrol# for profiling. See xref:OProfile.adoc#s1-using-operf[Using operf] for details.
For differences between [command]#operf# and [command]#opcontrol# see xref:OProfile.adoc#s2-operf_vs_opcontrol[operf vs. opcontrol].
|[command]#opreport#|Retrieves profile data. See xref:OProfile.adoc#s2-oprofile-reading-opreport[Using [command]#opreport#] for details.
|[command]#oprofiled#|Runs as a daemon to periodically write sample data to disk.
operf vs. opcontrol
There are two mutually exclusive methods for collecting profiling data with OProfile. You can either use the newer and preferred [command]#operf# or the [command]#opcontrol# tool.
operf
This is the recommended mode for profiling. The [command]#operf# tool uses the Linux Performance Events Subsystem, and therefore does not require the *oprofile* kernel driver. The [command]#operf# tool allows you to target your profiling more precisely, as a single process or system-wide, and also allows OProfile to co-exist better with other tools using the performance monitoring hardware on your system. Unlike [command]#opcontrol#, it can be used without the `root` privileges. However, [command]#operf# is also capable of system-wide operations with use of the [option]`--system-wide` option, where root authority is required.
With [command]#operf#, there is no initial setup needed. You can invoke [command]#operf# with command-line options to specify your profiling settings. After that, you can run the OProfile post-processing tools described in xref:OProfile.adoc#s1-oprofile-analyzing-data[Analyzing the Data]. See xref:OProfile.adoc#s1-using-operf[Using operf] for further information.