Why OProfile?
Sometimes you want to get an idea were bottlenecks lie, and oprofile is ideal for that. It's a statistical profiler for linux. It requires kernel support (CONFIG_OPROFILE).
Basic howto
Install oprofile and make sure your kernel supports it.
Setting kernel image. Yes, this is really vmlinux, not bzImage. You may find it in your kernel source tree after compiling.
opcontrol --vmlinux=/path/to/vmlinux
or if you do not have it
opcontrol --no-vmlinux
- Setting call graph depth (optional, for x86 and PPC only)
opcontrol --callgraph=6
- Delete old oprofile results
opcontrol --reset
- Start profiling
opcontrol --start
- Do the thing you wanted to profile.
- Make sure all profile data gets into files.
opcontrol --dump
- Stop profiling.
opcontrol --stop
- Various commands to see the results:
opreport
opreport -l
opreport -l /path/to/specific/module/or/application
opreport --callgraph
- Unload oprofile
opcontrol --deinit
Alternatively, you can use a modified version of Carl Worth's oprofile script that can be found [here:http://cworth.org/bin/profile]. Change the paths to match the ones of your system.
Notes
The callgraph function can provide some hints were function calls are coming from, you just have to get familiar with them before you understand them. Please be aware that optimisation leads to inlining of functions and this affects profiling just as it affects debugging. You'll need to request a callgraph depth for this to work. On some architectures such as x86_64 you need to add "-fno-omit-frame-pointer" to your CFLAGS.
If you want to get kernel symbols, you'll need to add the path to vmlinux, this is not the compressed image. It can usually be found in /usr/src/linux/vmlinux if you compiled your own kernel.