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 @@ ...@@ -7,6 +7,7 @@
import argparse import argparse
import curses import curses
import logging
import os import os
import re import re
import sys import sys
...@@ -127,27 +128,13 @@ class DeviceHelper(object): ...@@ -127,27 +128,13 @@ class DeviceHelper(object):
intersect the two. The returned result is sorted based on userid.""" intersect the two. The returned result is sorted based on userid."""
pids = [] pids = []
try: try:
# TODO(catapult:#3215): Migrate to adb.GetPids(). for process in adb.ListProcesses(process_filter):
pid_lines = adb.RunShellCommand( if default_pid and process.pid != default_pid:
['ps'], large_output=True, check_return=True) continue
if default_pid: userid = DeviceHelper.__GetUserIdForProcessName(adb, process.name)
pid_lines = Utils.FindLines(pid_lines, str(default_pid)) pids.append((userid, process.pid, process.name))
if process_filter: except device_errors.AdbShellCommandFailedError as exc:
pid_lines = Utils.FindLines(pid_lines, process_filter) logging.warning('Error getting PIDs to track: %s', exc)
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
return sorted(pids, key=lambda tup: tup[0]) return sorted(pids, key=lambda tup: tup[0])
class NetworkHelper(object): 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