Added pid initializer using ps command

This commit is contained in:
Poly Takahiro Horikawa
2013-08-21 15:02:07 -07:00
parent 1e997a26e8
commit 18674c501c
+35 -4
View File
@@ -137,15 +137,21 @@ PID_DEATH = re.compile(r'^Process ([a-zA-Z0-9._]+) \(pid (\d+)\) has died.?$')
LOG_LINE = re.compile(r'^([A-Z])/(.+?)\( *(\d+)\): (.*?)$') LOG_LINE = re.compile(r'^([A-Z])/(.+?)\( *(\d+)\): (.*?)$')
BUG_LINE = re.compile(r'.*nativeGetEnabledTags.*') BUG_LINE = re.compile(r'.*nativeGetEnabledTags.*')
adb_command = ['adb'] adb_options = []
if args.device_serial: if args.device_serial:
adb_command.extend(['-s', args.device_serial]) adb_options.extend(['-s', args.device_serial])
if args.use_device: if args.use_device:
adb_command.append('-d') adb_options.append('-d')
if args.use_emulator: if args.use_emulator:
adb_command.append('-e') adb_options.append('-e')
adb_command = ['adb']
adb_command.extend(adb_options)
adb_command.append('logcat') adb_command.append('logcat')
ps_command = ['adb']
ps_command.extend(adb_options)
ps_command.extend(['shell', 'ps'])
adb = subprocess.Popen(adb_command, stdin=PIPE, stdout=PIPE, stderr=PIPE) adb = subprocess.Popen(adb_command, stdin=PIPE, stdout=PIPE, stderr=PIPE)
pids = set() pids = set()
last_tag = None last_tag = None
@@ -174,6 +180,31 @@ def parse_death(tag, message):
return pid return pid
return None return None
def parse_ps(ps_out, set):
processes = ps_out.split('\n')
fields = processes[0].split();
nfields = len(fields)
for row in processes[1:]:
row = row.rstrip()
if not row:
continue
fields = row.split(None, nfields)
name = fields[8]
pid = fields[1]
if match_packages(name):
linebuf = '\n'
linebuf += colorize(' ' * (header_size - 1), bg=WHITE)
linebuf += ' Process %s is found' % (pid)
linebuf += '\n'
print(linebuf)
pids.add(pid)
def update_with_ps():
ps = subprocess.Popen(ps_command, stdout=PIPE)
ps_out, ps_err = ps.communicate()
parse_ps(ps_out, set)
update_with_ps()
while adb.poll() is None: while adb.poll() is None:
try: try:
line = adb.stdout.readline().decode('utf-8', 'replace').strip() line = adb.stdout.readline().decode('utf-8', 'replace').strip()