blob: b095e77d5b4236b6211ba1113075e1c097d9e39a [file] [log] [blame]
Jeff Brown87866d92011-02-02 13:27:17 -08001#!/usr/bin/env python2.6
2#
3# Copyright (C) 2011 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#
17
18#
19# Remotely controls an OProfile session on an Android device.
20#
21
22import os
23import sys
24import getopt
25
26class Adb:
27 def __init__(self, serial_number):
28 self._default_args = ''
29 if serial_number != None:
30 self._default_args = '-s ' + serial_number
31
32 def shell(self, command):
33 result = os.system('adb%s shell %s' % (self._default_args, command)
34 return result
35
36def usage():
37 print "Usage:" + sys.argv[0]
38 print " -h, --help : show this help text"
39 print " -s, --serial=number : the serial number of the device being profiled"
40 print " --setup : setup profiler"
41 print " --start : start profiling"
42 print " --stop : stop profiling"
43 print
44
45def main():
46 try:
47 opts, args - getopt.getopt(sys.argv[1:], "hs:", ["help", "serial=", "setup", "start", "stop"])
48 except getopt.GetoptError, e:
49 usage()
50 print str(e)
51 sys.exit(1)
52
53 serial_number = None
54 command = None
55 for o, a in opts:
56 if o in ('-h', '--help'):
57 usage()
58 sys.exit()
59 elif o in ('-s', '--serial'):
60 serial_number = a
61 elif o in ('--setup'):
62 command = 'setup'
63 elif o in ('--start'):
64 command = 'start'
65 elif o in ('--stop'):
66 command = 'stop'
67 else:
68 assert False, 'unhandled option' + o
69
70 adb = Adb(serial_number)
71
72 if command == 'setup':
73 setup(adb)
74 elif command == 'start':
75 start(adb)
76 elif command == 'stop':
77 stop(adb)
78 else:
79 usage()
80 print 'A command must be specified.'
81 sys.exit(1)
82
83def setup(adb):
84 adb.shell
85
86 pass
87
88def start(adb):
89 pass
90
91def stop(adb):
92 pass
93
94main()