performance / tuning tips. to the point.
|
Profiling CPU on Linux with oprofile
If you are performance-testing applications on Linux, then you would want to know oprofile. It is the equivalent of
similar tools like
tprof on AIX.
oprofile isn't hard to use at all, and quite the opposite from what people think, it is easy to use, and it casues low overhead on your system.
In most instances, you will only use two of the commands that oprofile provides:
opcontrol and opreport. The
opcontrol command configures oprofile and
manages the kernel and userspace profiling components, while the opreport command generates reports.
You can read the manuals to know more about the tool on its web site, but here are several usages that can get you start right away (after you installed it).
rpm -ql kernel-debuginfo | grep vmlinux
/usr/lib/debug/lib/modules/2.6.18-1.2849.fc6/vmlinux
opcontrol --setup --vmlinux=/usr/lib/debug/lib/modules/2.6.18-1.2849.fc6/vmlinux
opcontrol --start
opcontrol --stop
opcontrol --dump
opcontrol --save oprofile.myoutput // use your session name here
opreport session:oprofile.myoutput // that name used througout opreport commands below
opreport session:oprofile.myoutput --long-filenames
opreport session:oprofile.myoutput --long-filenames > /home/pwstaff/op1.out
// look in op1.out to spot the top CPU consumers, then on them, run...
opreport session:oprofile.myoutput -l image:/net2/mylibrary.so.1 --include-symbols > /home/pwstaff/op2.out
opreport session:oprofile.myoutput -l image:/net2/mylibrary.so.1 --include-symbols --details > /home/pwstaff/op3.out
|
You may also rsh and call the command remotely and save outputs during your test run (that is, to automate it)
outsystemdir=$OUTDIR/system
if [ ! -d $outsystemdir ] ; then mkdir -p $outsystemdir ; fi
rsh -l $ADM_USERNAME $NODE $PROFILER_HOME/opcontrol --start --callgraph=0 --vmlinux=$KERNEL_SRC_PATH/vmlinux
rsh -l $ADM_USERNAME $NODE $PROFILER_HOME/opcontrol --reset
sleep $SLEEPTIME;
rsh -l $ADM_USERNAME $NODE $PROFILER_HOME/opcontrol --dump
rsh -l $ADM_USERNAME $NODE $PROFILER_HOME/opreport -f --symbols > $outsystemdir/prof1.$NODE
rsh -l $ADM_USERNAME $NODE $PROFILER_HOME/opreport -c -f --symbols > $outsystemdir/prof2.$NODE
rsh -l $ADM_USERNAME $NODE $PROFILER_HOME/opreport --symbols > $outsystemdir/prof3.$NODE
rsh -l $ADM_USERNAME $NODE $PROFILER_HOME/opreport -d --symbols > $outsystemdir/prof4.$NODE
rsh -l $ADM_USERNAME $NODE $PROFILER_HOME/opcontrol --stop
rsh -l $ADM_USERNAME $NODE $PROFILER_HOME/opcontrol --shutdown
|
Some example output opreport generates (from oprofile web site, used
under license agreement):


|
|
|