blob: bc443ec198f8693b4d25ae44d62e57a86b04a393 [file] [log] [blame]
#!/usr/bin/python2.4 -E
import os
import re
import sys
def PrintUsage():
print "Usage:" + sys.argv[0] + " [-r] dir"
print " -r : reuse the directory if it already exists"
print " dir: directory on the host to store profile results"
if (len(sys.argv) > 3):
PrintUsage()
sys.exit(1)
# identify 32-bit vs 64-bit platform
stream = os.popen("uname -m")
arch_name = stream.readline().rstrip("\n");
stream.close()
# default path is prebuilt/linux-x86/oprofile
# for 64-bit OS, use prebuilt/linux-x86_64/oprofile instead
if arch_name == "x86_64":
arch_path = "/../../linux-x86_64/oprofile"
else:
arch_path = ""
try:
oprofile_event_dir = os.environ['OPROFILE_EVENTS_DIR']
except:
print "OPROFILE_EVENTS_DIR not set. Run \". envsetup.sh\" first"
sys.exit(1)
if sys.argv[1] == "-r" :
replace_dir = 1
output_dir = sys.argv[2]
else:
replace_dir = 0
output_dir = sys.argv[1]
if (os.path.exists(output_dir) and (replace_dir == 1)):
os.system("rm -fr " + output_dir)
try:
os.makedirs(output_dir)
except:
if os.path.exists(output_dir):
print "Directory already exists:", output_dir
print "Try \"" + sys.argv[0] + " -r " + output_dir + "\""
else:
print "Cannot create", output_dir
sys.exit(1)
# get the samples off the phone
result = os.system("adb pull /data/oprofile/samples " + output_dir + \
"/raw_samples > /dev/null 2>&1")
if result != 0:
print "adb pull failure, exiting"
sys.exit(1)
# enter the destination directory
os.chdir(output_dir)
stream = os.popen("find raw_samples -type f -name \*all")
# now all the sample files are on the host, we need to invoke opimport one at a
# time to convert the content from the ARM abi to x86 ABI
# break the full filename into:
# 1: leading dir: "raw_samples"
# 2: intermediate dirs: "/blah/blah/blah"
# 3: filename: e.g. "CPU_CYCLES.150000.0.all.all.all"
pattern = re.compile("(^raw_samples)(.*)/(.*)$")
for line in stream:
match = pattern.search(line)
leading_dir = match.group(1)
middle_part = match.group(2)
file_name = match.group(3)
dir = "samples" + middle_part
# if multiple events are collected the directory could have been setup
if not os.path.exists(dir):
os.makedirs(dir)
cmd = oprofile_event_dir + arch_path + "/bin/opimport -a " + \
oprofile_event_dir + \
"/abi/arm_abi -o samples" + middle_part + "/" + file_name + " " + line
os.system(cmd)
stream.close()
# short summary of profiling results
os.system(oprofile_event_dir + arch_path + "/bin/opreport --session-dir=.")