2009年12月8日 星期二

Using OProfile



Build Requirement
binutils
popt


Required Kernel Config
CONFIG_SMP cannot be enabled in ARM11 MPCore, due to arch/arm/oprofile/op_model_mpcore.c is arch/arm/mach-realview/ specific.

Linux 2.6.35.12

General setup --->
[*] Profiling support
<M> OProfile system profiling


kernel modules must be built with "-g" and not stripped. Since compiler can optimize code to further improve the performance, "-O3"
is suggested.
Kernel hacking --->
[*] Kernel debugging
[*] Compile the kernel with debug info


To support call-graph profile, kernel and modules must NOT be built with gcc's -fomit-frame-pointer, or enable the CONFIG_FRAME_POINTER. But only x86 has CONFIG_ARCH_WANT_FRAME_POINTERS enabled on 2.6.35.
Kernel hacking --->
[*]Compile the kernel with frame pointers


Required tools
awk, objdump

Required files
vmlinux is required as input to oprofile.
An external disk maybe required, for the log and samples, stored at /var/lib/oprofile/, and vmlinux, may take up to tens of MBs.
Commands
opcontrol --reset;
opcontrol --setup --vmlinux=<vmlinux_path>
opcontrol --start -V all;
opcontrol --shutdown;
opreport image:<vmlinux_path>,<module_path> -p <module_dir> -l -g -w

References
4. Configuration details
http://oprofile.sourceforge.net/doc/detailed-parameters.html
4.3. OProfile in timer interrupt mode
Note
This section applies to 2.6 kernels and above only.

In 2.6 kernels on CPUs without OProfile support for the hardware performance counters, the driver falls back to using the timer interrupt for profiling. Like the RTC mode in 2.4 kernels, this is not able to profile code that has interrupts disabled. Note that there are no configuration parameters for setting this, unlike the RTC and hardware performance counter setup.

You can force use of the timer interrupt by using the timer=1 module parameter (or oprofile.timer=1 on the boot command line if OProfile is built-in).


3. Interpreting call-graph profiles
http://oprofile.sourceforge.net/doc/interpreting-callgraph.html

OProfile usage
http://blog.chinaunix.net/space.php?uid=20585891&do=blog&cuid=1110505

使用oprofile分析性能瓶頸(1)
http://tw.myblog.yahoo.com/chimei-015/article?mid=1023&prev=1024&next=1022

oprofile抓不到采样数据问题和解决方法
http://blog.yufeng.info/archives/1283


warning: /no-vmlinux could not be found.

OProfile unable to find image.
http://old.nabble.com/OProfile-unable-to-find-image.-td29336543.html
The "--no-vmlinux" option is used when you are not interested in analyzing the samples from the kernel. The samples from the kernel are recorded in /novmlinux. However, the needed information used by opreport is missing.

CPU: CPU with timer interrupt, speed 0 MHz (estimated)

OProfile get cpu speed by parsing /proc/cpuinfo. Just it's not found what it expect.
libutil/op_cpufreq.c
double op_cpu_frequency(void)
{

(................)

FILE * fp = op_try_open_file("/proc/cpuinfo", "r");

(................)

/* x86/parisc/ia64/x86_64 */
if (sscanf(line, "cpu MHz : %lf", &fval) == 1)
break;
/* ppc/ppc64 */
if (sscanf(line, "clock : %lfMHz", &fval) == 1)
break;
/* alpha */
if (sscanf(line, "cycle frequency [Hz] : %lu", &uval) == 1) {
fval = uval / 1E6;
break;
}
/* sparc64 if CONFIG_SMP only */
if (sscanf(line, "Cpu0ClkTck : %lx", &uval) == 1) {
fval = uval / 1E6;
break;
}

沒有留言: