The Android Open Source Project | 10e23ee | 2009-03-03 19:30:30 -0800 | [diff] [blame] | 1 | #!/usr/bin/python2.4 -E |
| 2 | |
| 3 | import os |
| 4 | import re |
| 5 | import sys |
| 6 | |
| 7 | def PrintUsage(): |
| 8 | print "Usage:" + sys.argv[0] + " dir" |
| 9 | print " dir: directory on the host to store profile results" |
| 10 | |
| 11 | if (len(sys.argv) != 2): |
| 12 | PrintUsage() |
| 13 | sys.exit(1) |
| 14 | |
| 15 | try: |
| 16 | oprofile_event_dir = os.environ['OPROFILE_EVENTS_DIR'] |
| 17 | except: |
| 18 | print "OPROFILE_EVENTS_DIR not set. Run \". envsetup.sh\" first" |
| 19 | sys.exit(1) |
| 20 | |
| 21 | output_dir = sys.argv[1]; |
| 22 | |
| 23 | try: |
| 24 | os.makedirs(output_dir) |
| 25 | except: |
| 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 |
| 33 | result = os.system("adb pull /data/oprofile/samples " + output_dir + \ |
| 34 | "/raw_samples > /dev/null 2>&1") |
| 35 | if result != 0: |
| 36 | print "adb pull failure, exiting" |
| 37 | sys.exit(1) |
| 38 | |
| 39 | # enter the destination directory |
| 40 | os.chdir(output_dir) |
| 41 | stream = 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" |
| 50 | pattern = re.compile("(^raw_samples)(.*)/(.*)$") |
| 51 | for 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 | |
| 67 | stream.close() |
| 68 | |
| 69 | # short summary of profiling results |
| 70 | os.system(oprofile_event_dir + "/bin/opreport --session-dir=.") |