Commit e198a121 authored by Juan Antonio Navarro Perez's avatar Juan Antonio Navarro Perez Committed by Commit Bot

[tools/android] Simplify GetPidsToTrack implementation

The device_utils.ListProcesses method already does most of the work
required to implement GetPidsToTrack. Use that rather than hand-rolling
yet another parse-grepping through the output of `ps`.

Bug: catapult:#3215
Bug: catapult:#4103
Change-Id: I3825761ce2efc6cbdd940f41505789b61506bd8b
Reviewed-on: https://chromium-review.googlesource.com/955628Reviewed-by: default avatarJohn Budorick <jbudorick@chromium.org>
Commit-Queue: Juan Antonio Navarro Pérez <perezju@chromium.org>
Cr-Commit-Position: refs/heads/master@{#542112}
parent bec91121
......@@ -7,6 +7,7 @@
import argparse
import curses
import logging
import os
import re
import sys
......@@ -127,27 +128,13 @@ class DeviceHelper(object):
intersect the two. The returned result is sorted based on userid."""
pids = []
try:
# TODO(catapult:#3215): Migrate to adb.GetPids().
pid_lines = adb.RunShellCommand(
['ps'], large_output=True, check_return=True)
if default_pid:
pid_lines = Utils.FindLines(pid_lines, str(default_pid))
if process_filter:
pid_lines = Utils.FindLines(pid_lines, process_filter)
for line in pid_lines:
data = re.split('\s+', line.strip())
pid = data[1]
name = data[-1]
# Confirm that the pid and name match. Using a regular grep isn't
# reliable when doing it on the whole 'ps' input line.
pid_matches = not default_pid or pid == str(default_pid)
name_matches = not process_filter or name.find(process_filter) != -1
if pid_matches and name_matches:
userid = DeviceHelper.__GetUserIdForProcessName(adb, name)
pids.append((userid, pid, name))
except device_errors.AdbShellCommandFailedError:
pass
for process in adb.ListProcesses(process_filter):
if default_pid and process.pid != default_pid:
continue
userid = DeviceHelper.__GetUserIdForProcessName(adb, process.name)
pids.append((userid, process.pid, process.name))
except device_errors.AdbShellCommandFailedError as exc:
logging.warning('Error getting PIDs to track: %s', exc)
return sorted(pids, key=lambda tup: tup[0])
class NetworkHelper(object):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment