2. Getting started with OProfile using legacy profiling mode

Before you can use OProfile's legacy profiling mode, you must set it up. The minimum setup required for this is to tell OProfile where the vmlinux file corresponding to the running kernel is, for example :

opcontrol --vmlinux=/boot/vmlinux-`uname -r`

If you don't want to profile the kernel itself, you can tell OProfile you don't have a vmlinux file :

opcontrol --no-vmlinux

Now we are ready to start the daemon (oprofiled) which collects the profile data :

opcontrol --start

When you want to stop profiling, you can do so with :

opcontrol --shutdown

Note that unlike gprof, no instrumentation (-pg and -a options to gcc) is necessary.

Periodically (or on opcontrol --shutdown or opcontrol --dump) the profile data is written out into the $SESSION_DIR/samples directory (by default at /var/lib/oprofile/samples). These profile files cover shared libraries, applications, the kernel (vmlinux), and kernel modules. You can clear the profile data (at any time) with opcontrol --reset.

To place these sample database files in a specific directory instead of the default location (/var/lib/oprofile) use the --session-dir=dir option. You must also specify the --session-dir to tell the tools to continue using this directory.

opcontrol --no-vmlinux --session-dir=/home/me/tmpsession
opcontrol --start --session-dir=/home/me/tmpsession

You can get summaries of this data in a number of ways at any time. To get a summary of data across the entire system for all of these profiles, you can do :

opreport [--session-dir=dir]

Or to get a more detailed summary, for a particular image, you can do something like :

opreport -l /boot/vmlinux-`uname -r`

There are also a number of other ways of presenting the data, as described later in this manual. Note that OProfile will choose a default profiling setup for you. However, there are a number of options you can pass to opcontrol if you need to change something, also detailed later.