blob: 7dbac4ac717cb3c01680976fe82f027eb5f6a1d1 [file] [log] [blame]
The Android Open Source Project7984f7a2008-12-17 18:04:47 -08001#!/usr/bin/python2.4 -E
2
3import os
4import re
5import sys
6
7def PrintUsage():
8 print "Usage:" + sys.argv[0] + " dir"
9 print " dir: directory on the host to store profile results"
10
11if (len(sys.argv) != 2):
12 PrintUsage()
13 sys.exit(1)
14
15try:
16 oprofile_event_dir = os.environ['OPROFILE_EVENTS_DIR']
17except:
18 print "OPROFILE_EVENTS_DIR not set. Run \". envsetup.sh\" first"
19 sys.exit(1)
20
21output_dir = sys.argv[1];
22
23try:
24 os.makedirs(output_dir)
25except:
26 if os.path.exists(output_dir):
27 print "Directory already exists:", output_dir
28 else:
29 print "Cannot create", output_dir
30 sys.exit(1)
31
32# get the samples off the phone
33result = os.system("adb pull /data/oprofile/samples " + output_dir + \
34 "/raw_samples > /dev/null 2>&1")
35if result != 0:
36 print "adb pull failure, exiting"
37 sys.exit(1)
38
39# enter the destination directory
40os.chdir(output_dir)
41stream = os.popen("find raw_samples -type f -name \*all")
42
43# now all the sample files are on the host, we need to invoke opimport one at a
44# time to convert the content from the ARM abi to x86 ABI
45
46# break the full filename into:
47# 1: leading dir: "raw_samples"
48# 2: intermediate dirs: "/blah/blah/blah"
49# 3: filename: e.g. "CPU_CYCLES.150000.0.all.all.all"
50pattern = re.compile("(^raw_samples)(.*)/(.*)$")
51for line in stream:
52 match = pattern.search(line)
53 leading_dir = match.group(1)
54 middle_part = match.group(2)
55 file_name = match.group(3)
56
57 dir = "samples" + middle_part
58
59 # if multiple events are collected the directory could have been setup
60 if not os.path.exists(dir):
61 os.makedirs(dir)
62
63 cmd = oprofile_event_dir + "/bin/opimport -a " + oprofile_event_dir + \
64 "/abi/arm_abi -o samples" + middle_part + "/" + file_name + " " + line
65 os.system(cmd)
66
67stream.close()
68
69# short summary of profiling results
70os.system(oprofile_event_dir + "/bin/opreport --session-dir=.")