oprofile

First you have to enable oprofile in your kernel, i.e. you must have

1
2
CONFIG_PROFILING=y
CONFIG_OPROFILE=y

in your kernel config. Then you need userspace utilities to use it. I used oprofile 0.9.4. First of all you need to setup it with something like

1
2
3
opcontrol --init
opcontrol --no-vmlinux
opcontrol --callgraph=5

After that, here is the script I used to do profiling against a program:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
john@buddha:~$ cat bin/profile
#!/bin/sh

which sudo && SUDO=sudo || SUDO=
which sudo && SUDO=sudo || SUDO=

${SUDO} opcontrol --shutdown
${SUDO} rm -rf /var/lib/oprofile/*
${SUDO} opcontrol --status
${SUDO} opcontrol --start-daemon
${SUDO} opcontrol --start
$@
${SUDO} opcontrol --stop
${SUDO} opcontrol --dump
${SUDO} opcontrol --shutdown

Use profile <the name of your executable> to get the profile. Use opreport to read the result. opreport -l might be more meaningful. You can use opreport <the name of your executable> to only get the result related to your program, but personally I prefer to check the whole system.