First you need to build OProfile and install it. ./configure, make, make install is often all you need, but note these arguments to ./configure :
--with-linux
Use this option to specify the location of the kernel source tree you wish to compile against. The kernel module is built against this source and will only work with a running kernel built from the same source with exact same options, so it is important you specify this option if you need to.
--with-kernel-support
Use this option with 2.6 and above kernels to indicate the kernel provides the OProfile device driver.
--with-qt-dir/includes/libraries
Specify the location of Qt headers and libraries. It defaults to searching in
$QTDIR if these are not specified.
--disable-werror
Development versions of OProfile build by
default with -Werror. This option turns
-Werror off.
--disable-optimization
Disable the -O2 compiler flag
(useful if you discover an OProfile bug and want to give a useful
back-trace etc.)
You'll need to have a configured kernel source for the current kernel to build the module for 2.4 kernels. Since all distributions provide different kernels it's unlikely the running kernel match the configured source you installed. The safest way is to recompile your own kernel, run it and compile oprofile. It is also recommended that if you have a uniprocessor machine, you enable the local APIC / IO_APIC support for your kernel (this is automatically enabled for SMP kernels). With many BIOS, kernel >= 2.6.9 and UP kernel it's not sufficient to enable the local APIC you must also turn it on explicitely at boot time by providing "lapic" option to the kernel. On machines with power management, such as laptops, the power management must be turned off when using OProfile with 2.4 kernels. The power management software in the BIOS cannot handle the non-maskable interrupts (NMIs) used by OProfile for data collection. If you use the NMI watchdog, be aware that the watchdog is disabled when profiling starts, and not re-enabled until the OProfile module is removed (or, in 2.6, when OProfile is not running). If you compile OProfile for a 2.2 kernel you must be root to compile the module. If you are using 2.6 kernels or higher, you do not need kernel source, as long as the OProfile driver is enabled; additionally, you should not need to disable power management.
Please note that you must save or have available the vmlinux file
generated during a kernel compile, as OProfile needs it (you can use
--no-vmlinux, but this will prevent kernel profiling).