blob: bc443ec198f8693b4d25ae44d62e57a86b04a393 [file] [log] [blame]
The Android Open Source Project10e23ee2009-03-03 19:30:30 -08001#!/usr/bin/python2.4 -E
2
3import os
4import re
5import sys
6
7def PrintUsage():
Ben Chengd6eeae32009-10-07 12:28:49 -07008 print "Usage:" + sys.argv[0] + " [-r] dir"
9 print " -r : reuse the directory if it already exists"
The Android Open Source Project10e23ee2009-03-03 19:30:30 -080010 print " dir: directory on the host to store profile results"
11
Ben Chengd6eeae32009-10-07 12:28:49 -070012if (len(sys.argv) > 3):
The Android Open Source Project10e23ee2009-03-03 19:30:30 -080013 PrintUsage()
14 sys.exit(1)
15
Ben Chengd6eeae32009-10-07 12:28:49 -070016# identify 32-bit vs 64-bit platform
17stream = os.popen("uname -m")
18arch_name = stream.readline().rstrip("\n");
19stream.close()
20
21# default path is prebuilt/linux-x86/oprofile
22# for 64-bit OS, use prebuilt/linux-x86_64/oprofile instead
23if arch_name == "x86_64":
24 arch_path = "/../../linux-x86_64/oprofile"
25else:
26 arch_path = ""
27
The Android Open Source Project10e23ee2009-03-03 19:30:30 -080028try:
29 oprofile_event_dir = os.environ['OPROFILE_EVENTS_DIR']
30except:
31 print "OPROFILE_EVENTS_DIR not set. Run \". envsetup.sh\" first"
32 sys.exit(1)
33
Ben Chengd6eeae32009-10-07 12:28:49 -070034if sys.argv[1] == "-r" :
35 replace_dir = 1
36 output_dir = sys.argv[2]
37else:
38 replace_dir = 0
39 output_dir = sys.argv[1]
40
41if (os.path.exists(output_dir) and (replace_dir == 1)):
42 os.system("rm -fr " + output_dir)
The Android Open Source Project10e23ee2009-03-03 19:30:30 -080043
44try:
45 os.makedirs(output_dir)
46except:
47 if os.path.exists(output_dir):
48 print "Directory already exists:", output_dir
Ben Chengd6eeae32009-10-07 12:28:49 -070049 print "Try \"" + sys.argv[0] + " -r " + output_dir + "\""
The Android Open Source Project10e23ee2009-03-03 19:30:30 -080050 else:
51 print "Cannot create", output_dir
52 sys.exit(1)
53
54# get the samples off the phone
55result = os.system("adb pull /data/oprofile/samples " + output_dir + \
56 "/raw_samples > /dev/null 2>&1")
57if result != 0:
58 print "adb pull failure, exiting"
59 sys.exit(1)
60
61# enter the destination directory
62os.chdir(output_dir)
63stream = os.popen("find raw_samples -type f -name \*all")
64
65# now all the sample files are on the host, we need to invoke opimport one at a
66# time to convert the content from the ARM abi to x86 ABI
67
68# break the full filename into:
69# 1: leading dir: "raw_samples"
70# 2: intermediate dirs: "/blah/blah/blah"
71# 3: filename: e.g. "CPU_CYCLES.150000.0.all.all.all"
72pattern = re.compile("(^raw_samples)(.*)/(.*)$")
73for line in stream:
74 match = pattern.search(line)
75 leading_dir = match.group(1)
76 middle_part = match.group(2)
77 file_name = match.group(3)
78
79 dir = "samples" + middle_part
80
81 # if multiple events are collected the directory could have been setup
82 if not os.path.exists(dir):
83 os.makedirs(dir)
84
Ben Chengd6eeae32009-10-07 12:28:49 -070085 cmd = oprofile_event_dir + arch_path + "/bin/opimport -a " + \
86 oprofile_event_dir + \
The Android Open Source Project10e23ee2009-03-03 19:30:30 -080087 "/abi/arm_abi -o samples" + middle_part + "/" + file_name + " " + line
88 os.system(cmd)
89
90stream.close()
91
92# short summary of profiling results
Ben Chengd6eeae32009-10-07 12:28:49 -070093os.system(oprofile_event_dir + arch_path + "/bin/opreport --session-dir=.")