Questo contenuto non è disponibile nella lingua selezionata.
5.2. OProfile
OProfile is a low overhead, system-wide performance monitoring tool provided by the oprofile package. 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 second-level cache requests, and the number of hardware interrupts received. OProfile is also able to profile applications that run in a Java Virtual Machine (JVM).
The following is a selection of the tools provided by OProfile. Note that the legacy
opcontrol
tool and the new operf
tool are mutually exclusive.
- ophelp
- Displays available events for the system’s processor along with a brief description of each.
- operf
- Intended to replace
opcontrol
. Theoperf
tool uses the Linux Performance Events subsystem, allowing you to target your profiling more precisely, as a single process or system-wide, and allowing OProfile to co-exist better with other tools using the performance monitoring hardware on your system. Unlikeopcontrol
, no initial setup is required, and it can be used without the root privileges unless the--system-wide
option is in use. - 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.
- opannotate
- Creates an annotated source for an executable if the application was compiled with debugging symbols.
- opreport
- Retrieves profile data.
- opcontrol
- This tool is used to start and stop the OProfile daemon (
oprofiled
) and configure a profile session. - oprofiled
- Runs as a daemon to periodically write sample data to disk.
Legacy mode (
opcontrol
, oprofiled
, and post-processing tools) remains available, but it is no longer the recommended profiling method. For a detailed description of the legacy mode, see the Configuring OProfile Using Legacy Mode chapter in the System Administrator's Guide.
5.2.1. Using OProfile
operf
is the recommended tool for collecting profiling data. The tool does not require any initial configuration, and all options are passed to it on the command line. Unlike the legacy opcontrol
tool, operf
can run without root
privileges. See the Using operf chapter in the System Administrator's Guide for detailed instructions on how to use the operf
tool.
Example 5.1. Using operf to Profile a Java Program
In the following example, the
operf
tool is used to collect profiling data from a Java (JIT) program, and the opreport
tool is then used to output per-symbol data.
- Install the demonstration Java program used in this example. It is a part of the java-1.8.0-openjdk-demo package, which is included in the Optional channel. See Enabling Supplementary and Optional Repositories for instructions on how to use the Optional channel. When the Optional channel is enabled, install the package:
~]#
yum install java-1.8.0-openjdk-demo
- Install the oprofile-jit package for OProfile to be able to collect profiling data from Java programs:
~]#
yum install oprofile-jit
- Create a directory for OProfile data:
~]$
mkdir ~/oprofile_data
- Change into the directory with the demonstration program:
~]$
cd /usr/lib/jvm/java-1.8.0-openjdk/demo/applets/MoleculeViewer/
- Start the profiling:
~]$
operf -d ~/oprofile_data appletviewer \
-J"-agentpath:/usr/lib64/oprofile/libjvmti_oprofile.so" example2.html
- Change into the home directory and analyze the collected data:
~]$
cd
~]$
opreport --symbols --threshold 0.5
A sample output may look like the following:$ opreport --symbols --threshold 0.5 Using /home/rkratky/oprofile_data/samples/ for samples directory. WARNING! Some of the events were throttled. Throttling occurs when the initial sample rate is too high, causing an excessive number of interrupts. Decrease the sampling frequency. Check the directory /home/rkratky/oprofile_data/samples/current/stats/throttled for the throttled event names. warning: /dm_crypt could not be found. warning: /e1000e could not be found. warning: /kvm could not be found. CPU: Intel Ivy Bridge microarchitecture, speed 3600 MHz (estimated) Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000 samples % image name symbol name 14270 57.1257 libjvm.so /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.51-1.b16.el7_1.x86_64/jre/lib/amd64/server/libjvm.so 3537 14.1593 23719.jo Interpreter 690 2.7622 libc-2.17.so fgetc 581 2.3259 libX11.so.6.3.0 /usr/lib64/libX11.so.6.3.0 364 1.4572 libpthread-2.17.so pthread_getspecific 130 0.5204 libfreetype.so.6.10.0 /usr/lib64/libfreetype.so.6.10.0 128 0.5124 libc-2.17.so __memset_sse2