Anyone got oprofile running on Android kernel?

1,593 views
Skip to first unread message

Magnus

unread,
Apr 30, 2009, 9:08:55 AM4/30/09
to android-platform
Hi all,

I want to use oprofile and from other posts here there seems to be
someone who has been able to get it going. Maybe you can share some
advice?

I have built the kernel with profiling enabled. So, there is a
oprofilefs in /proc/filesystems. Also oprofilefs is mounted as can be
seen in /proc/mounts.

I have successfully cross-compiled the oprofile tools (profiled,
ophelp etc etc) and installed them on the emulator. In the opcontrol
script there are alot of assumptions that you are on a normal 2.6
kernel. It for examples assumes that /etc/mtab exists. It assumes
write access to a bunch of places where you normally don't have access
on the Android kernel (that is if you dont remount) etc etc.

Now, before starting to modify this opcontrol script (and find out if
this is possible at all) I wonder if you guys who have already done
this could perhaps share your knowledge (maybe also the script)? :)

Any advice greatly appreciated!
/Magnus

Vijay S. Yellapragada

unread,
May 1, 2009, 7:57:06 AM5/1/09
to android-...@googlegroups.com
Hi,

I have had some success in getting oprofile to run on the ADP1 phone.

First update the ADP1 to 1.5 images. It makes things simpler...You can
get the images from (http://www.htc.com/www/support/android/adp.html)

This is what I had to do :-

Sources
o Follow the instructions for building for the dream to update your master repo
o You need to build your own custom kernel which oprofile turned on.
For this I had to use the msm.git repo (git clone
git://android.git.kernel.org/kernel/msm.git). This kernel has all the
required patches...

Building the Kernel
o Start with make msm_defconfig and then modify the config to enable oprofile
o Cross compile the kernel using 4.2.1 arm-eabi toolchain
o export ARCH=arm
o export CROSS_COMPILE=<path to 4.2.1 tool chain>/arm-eabi-
o make

Building the boot.img
o cd to your master repo
o In your buildspec.mk, you need to add the following lines
TARGET_PRODUCT=htc_dream
TARGET_PREBUILT_KERNEL=<path to the built kernel> (e.g
..../kernel/arch/arm/boot/zImage)
o . build/envsetup.sh
o make

If all goes you should get a boot.img in out/target/product/dream/
which contains the kernel you built. You will also see the system.img,
userdata.img etc..

Flashing the phone
o fastboot flast boot boot.img (you can flash the other images if you
want as well)

Running oprofile
o The master repo has a oprofile directory in external/oprofile
o As part of the build process it builds oprofiled and opcontrol.
o Copy them to the phone( Although the phone contains versions in
/system/xbin, they seem to be the older versions)
o adb push opcontrol /data/local/ (the opcontrol in this case is not a
script, you can use the script version if you want, but then you need
to make sure you set the OPROFILE_EVENTS_DIR and session-dir to
something appropriate)
o adb push oprofiled /data/local/
o adb shell
o cd /data/local
o ./opcontrol --setup
o ./opcontrol --event=CPU_CYCLES:150000
o ./opcontrol --start
o ./opcontrol --status (make sure both the profiler and the daemon are running)
o profile your app
o opcontrol --stop
o If everything went well, you will see two directories {kern} and
{root} in your /data/oprofile/samples/current/

Post Processing
o Use the opimport_pull script in external/oprofile/ directory to pull
the sample and process them on the host.

Hope this helps.

- Vijay

Magnus

unread,
May 5, 2009, 3:23:35 AM5/5/09
to android-platform
I followed your instructions and building the kernel went fine. When
building the master I modified the buildspec.mk (I just copied the
buildspec.mk.default) and added the two lines you suggested. However,
when I try to "make" this I get the following error:

build/core/product_config.mk:173: *** No matches for product
"htc_dream". Stop.

I tried to build it with target = generic which works. However, this
does not result in a new boot.img. Only system.img, data.img and
ramdisk.img

Any more changes I need to consider?
/M

Magnus

unread,
May 5, 2009, 3:51:37 AM5/5/09
to android-platform
ok, got it..my bad. Just needed to rtfm a bit. First time building for
ADP1 so..:)..continuing..
/M

On May 1, 1:57 pm, "Vijay S. Yellapragada" <yell...@gmail.com> wrote:

Magnus

unread,
May 6, 2009, 4:11:47 AM5/6/09
to android-platform
It all works! thanks.

I tried to do this on the emulator as well but had problems with the
events and got no samples. However, I don't really know if there is a
point profiling on the emulator .

br
/Magnus

On May 1, 1:57 pm, "Vijay S. Yellapragada" <yell...@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages