This post records the basic flow to use oprofile tool on Android
OProfile consists of a Kernel driver and a daemon for collecting data. It makes use of the hardware performance counters provided on Intel, AMD, and other processors. OProfile is capable of profiling all code including the Kernel, Kernel modules, Kernel interrupt handlers, system shared libraries, and other applications.
Modern processors support profiling through the hardware by performance counters. Depending on the processor, there can be many counters and each of these can be programmed with an event to count. Each counter has a value which determines how often a sample is taken. The lower the value, the more often it is used.
During the post-processing step, all information is collected and instruction addresses are mapped to a function name.
Here we go ~
Add config, re-build kernel then flash into device
CONFIG_OPROFILE_ARMV7=y CONFIG_OPROFILE=y CONFIG_PROFILING=y CONFIG_HAVE_OPROFILE=y CONFIG_TRACEPOINTS=y
Build oprofile tool
$ source setbuildenv $ cd {root}/external/oprofile $ mm The output will be at "out/host/linux-x86/bin/"
Copy needed file
$ cp {root}/external/oprofile/events/arm/* /usr/local/share/oprofile/arm
Copy vmlinux into device (Optional, if you want to profile kernel)
$ adb push ${OUT}/obj/KERNEL/arch/arm/boot/compressed/vmlinux data/
Setup oprofile
opcontrol --setup --event=CPU_CYCLES:1500000 opcontrol --setup --vmlinux=/data/vmlinux --kernel-range=0xc00xxxxx,0xc0xxxxxx --event=CPU_CYCLES:1500000 (profile kernel) The option --kernel-range can be obtained from /proc/kallsyms. $ (adb shell cat /proc/kallsyms) | grep " _text" $ (adb shell cat /proc/kallsyms) | grep " _etext" or you could query System.map file $ grep " _text" System.map
Check status
opcontrol --status
Start profiling
opcontrol --start
Stop profiling
opcontrol --stop
Get profiling result
$ cd {root}/external/oprofile $ ./opimport_pull <result path>
Get a simple report
$ cd {root}/out/host/linux-x86/bin/ $ ./opreport --session-dir <result-path> -m all $ ./opreport -g -l -p <path-to-symbols> --session-dir <result-path>
Get annotated report
$ ./opannotate -p <path-to-symbols> -s -d <path-to-source-files-e.g.-mydroid> --session-dir <result-path>
Profiling based on thread
opcontrol --setup --event=CPU_CYCLES:1500000 --separate=thread // profiling based on thread $ ./opimport_pull <result-path> $ ./opreport --session-dir <result-path> -l tgid:[pid you want]
References
- OProfile manual
- Profiling the Android kernel and native applications using OProfile
- Profiling Tools - ftrace, perf, and oprofile
- how-to to oprofile 0xdroid
- oprofile 使用步驟 測試程序中各函數運行時間
- OProfile—System-Wide Profiler
--EOF--
No comments:
Post a Comment