[General Questions and Answers] MartinMueller2003:
Problem with oprofile on htc desire (bravo) - Resolved

I have gotten oprofile to work on a 2.6.35 based teamdesire kernel. I have included the sed lines from my scripts and a set of files I added to arc/arm/kernel.

In essence, the stock kernel does not recognize the scorpion cpu and the init.bravo file does not create an arm-pmu device to manage the Qualcomm PMU hardware. In early March Qualcomm published a patch to the 2.6.38 kernel that added partial scorpion support. That patch plus other changes is included in the attached files and implemented in the sed script snippets I have included here.

When the scripts are done you can control builing oprofile support by using the .config.oprofile vs .config.no.oprofile kernel config files

Here is what I do to create a report. NOTE: In my architecture I do not use opimport. It seems that opreport in ubuntu 10.04 LTS can read the arm files just fine. NOTE2: In my system adb is disabled so I cannot use adb pull (or I would).

set up the profiler

opcontrol --setup --event=CPU_CYCLES:15000:::1:1

start the profiler

opcontrol --start

stop the profiler - saves samples to ram

opcontrol --stop

copy the samples to the sdcard

cd /sdcard

mkdir oprofileSamples

cp -r /data/oprofile /sdcard/oprofileSamples/oprofile

move the files to the build machine (It MUST be the machine on which the files where built)

turn off the phone and move the sdcard to a computer

cp -r /sdcard/oprofileSamples/oprofile /someplaceOnTheBuildMachine/oprofileSamples/oprofile

Open up the update file and extract the Android environment to a single area. There are instructions on the web telling you how to do this

now get your report

cd /someplaceOnTheBuildMachine/oprofileSamples/oprofile - In this directory you should have a samples subdir and you should have an abi file.

opreport --symbols -g --session-dir=. -R /LocationOnTheBuildMachineYouHaveYourOutput/android/debug/image

###############################

# changes to the Android SDK to support oprofile

sed -i 's/ARM V7 PMNC", "arm\/armv7", CPU_ARM_V7, 5 },/ARM V7 PMNC", "arm\/armv7", CPU_ARM_V7, 5 },\

{ "ARM V7 SCORPION", "arm\/scorpion", CPU_ARM_V7, 5 },\

{ "ARM V7 SCORPIONMP", "arm\/scorpionMP", CPU_ARM_V7, 5 },/g' $SYSTEM_PATH/external/oprofile/libop/op_cpu_type.c || exit

sed -i 's/if (mkdir(OP_DATA_DIR, 755)) {/if (mkdir(OP_DATA_DIR, 0755)) {/g' $SYSTEM_PATH/external/oprofile/opcontrol/opcontrol.cpp || exit

sed -i 's/if (mkdir(OP_DATA_DIR"\/samples", 644)) {/if (mkdir(OP_DATA_DIR"\/samples", 0755)) {/g' $SYSTEM_PATH/external/oprofile/opcontrol/opcontrol.cpp || exit

sed -i 's/if (mkdir(OP_DRIVER_BASE, 644)) {/if (mkdir(OP_DRIVER_BASE, 644)) {\

if( EEXIST != errno )\

{/g' $SYSTEM_PATH/external/oprofile/opcontrol/opcontrol.cpp || exit

sed -i 's/if (system("mount -t oprofilefs nodev "OP_DRIVER_BASE)) {/}\

\

system("umount "OP_DRIVER_BASE);\

if (system("mount -t oprofilefs nodev "OP_DRIVER_BASE)) {/g' $SYSTEM_PATH/external/oprofile/opcontrol/opcontrol.cpp || exit

echo "Got here"

sed -i 's/python2.4 -E/python2 -E/g' $SYSTEM_PATH/external/oprofile/opimport_pull || exit

sed -i 's/\[-s serial_number\] \[-r\]/\[-s serial_number\] \[-i indir\] \[-r\]/g' $SYSTEM_PATH/external/oprofile/opimport_pull || exit

sed -i 's/serial_number: the device being profiled"/serial_number: the device being profiled"\

print " -i indir: directory on the host from which to read sample data"/g' $SYSTEM_PATH/external/oprofile/opimport_pull || exit

sed -i 's/"x86_64"/"x86_64_IgnoreMe"/g' $SYSTEM_PATH/external/oprofile/opimport_pull || exit

sed -i 's/arch_path = ""/arch_path = ""\

\

raw_samples_dir = "raw_samples"/g' $SYSTEM_PATH/external/oprofile/opimport_pull || exit

sed -i 's/if sys.argv\[1\] == "-s":/if (sys.argv\[1\] == "-s"):/g' $SYSTEM_PATH/external/oprofile/opimport_pull || exit

sed -i 's/os.makedirs(output_dir)/os.makedirs( output_dir + "\/" + raw_samples_dir )/g' $SYSTEM_PATH/external/oprofile/opimport_pull || exit

sed -i 's/if sys.argv\[argv_next\] == "-r" :/if sys.argv\[argv_next\] == "-i" :\

input_dir = "%s" % sys.argv\[argv_next+1\]\

print " input dir = ", input_dir\

skip_pull = 1\

argv_next = argv_next + 2\

else:\

skip_pull = 0\

input_dir = ""\

\

if sys.argv\[argv_next\] == "-r" :/g' $SYSTEM_PATH/external/oprofile/opimport_pull || exit

sed -i 's/output_dir = sys.argv\[argv_next+1\]/output_dir = sys.argv\[argv_next+1\]\

argv_next = argv_next + 1/g' $SYSTEM_PATH/external/oprofile/opimport_pull || exit

sed -i 's/get the samples off the phone/\

if (skip_pull == 1) :\

result = os.system("cp -r %s\/* %s\/raw_samples"\

" > \/dev\/null 2>\&1" % (input_dir, output_dir))\

if result != 0:\

print "failure to copy %s\/* %s\/raw_samples\/." % (input_dir, output_dir)\

sys.exit(1)\

else:/g' $SYSTEM_PATH/external/oprofile/opimport_pull || exit

sed -i 's/f -name \\\*all")/f -name \\\*\\\.\\\*\\\.\\\*")/g' $SYSTEM_PATH/external/oprofile/opimport_pull || exit

# end changes to the Android SDK support oprofile

###############################

###############################

# changes to the 2.6.35 team desire kernel support oprofile

sed -i 's,return "arm/armv7-ca9";,return "arm/armv7-ca9"; \

case ARM_PERF_PMU_ID_SCORPION: \

return "arm/scorpion"; \

case ARM_PERF_PMU_ID_SCORPIONMP: \

return "arm/scorpion-mp"; ,g' $KERNEL_PATH/arch/arm/oprofile/common.c || exit

sed -i 's/ARM_PERF_PMU_ID_CA9,/ARM_PERF_PMU_ID_CA9, \

ARM_PERF_PMU_ID_SCORPION,\

ARM_PERF_PMU_ID_SCORPIONMP,/g' $KERNEL_PATH/arch/arm/include/asm/perf_event.h || exit

cd $BUILD_OUTPUT_PATH || exit

svn export -N svn+ssh://$LOGNAME@linux2/common/svn/repos/infrastructure/vendor_src/android/$ANDROID_VERSION/$KERNEL_VENDOR-$MODEL-perf_event-patch >> /dev/null || exit

cd $KERNEL_PATH/arch/arm/kernel || exit

rm -f perf_event.*

tar -xf $BUILD_OUTPUT_PATH/$KERNEL_VENDOR-$MODEL-perf_event-patch || exit

cp $KERNEL_PATH/.config $KERNEL_PATH/.config.no.oprofile || exit

cp $KERNEL_PATH/.config $KERNEL_PATH/.config.oprofile || exit

sed -i 's/# CONFIG_PERF_EVENTS is not set/CONFIG_PERF_EVENTS=y/g' $KERNEL_PATH/.config.oprofile || exit

sed -i 's/# CONFIG_PERF_COUNTERS is not set/CONFIG_PERF_COUNTERS=y\

# CONFIG_DEBUG_PERF_USE_VMALLOC is not set/g' $KERNEL_PATH/.config.oprofile || exit

sed -i 's/# CONFIG_PROFILING is not set/CONFIG_PROFILING=y\

CONFIG_OPROFILE=y/g' $KERNEL_PATH/.config.oprofile || exit

sed -i 's/# CONFIG_HIGHMEM is not set/# CONFIG_HIGHMEM is not set\

CONFIG_HW_PERF_EVENTS=y/g' $KERNEL_PATH/.config.oprofile || exit

sed -i 's/CONFIG_HAVE_FUNCTION_TRACER=y/CONFIG_HAVE_FUNCTION_TRACER=y\

CONFIG_RING_BUFFER=y\

CONFIG_RING_BUFFER_ALLOW_SWAP=y/g' $KERNEL_PATH/.config.oprofile || exit

# end changes to support oprofile

###############################

Good luck and happy tuning.