diff options
author | achuith@chromium.org <achuith@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-07 23:54:21 +0000 |
---|---|---|
committer | achuith@chromium.org <achuith@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-07 23:54:21 +0000 |
commit | c48614e3f923714b8b690b745bec1937ddaeba6e (patch) | |
tree | 6450d5df84b51949f137ecf2a5d83772ab9feb0f /tools | |
parent | 1050383c1002546dd71cfc95d7dba8a7906bd744 (diff) | |
download | chromium_src-c48614e3f923714b8b690b745bec1937ddaeba6e.zip chromium_src-c48614e3f923714b8b690b745bec1937ddaeba6e.tar.gz chromium_src-c48614e3f923714b8b690b745bec1937ddaeba6e.tar.bz2 |
Fix pid calculation for browser on cros.
The correct browser process is the direct child of the session_manager.
BUG=241749
TEST=manual
NOTRY=True
Review URL: https://chromiumcodereview.appspot.com/16626005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@204980 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools')
-rw-r--r-- | tools/telemetry/telemetry/core/chrome/cros_browser_backend.py | 32 | ||||
-rw-r--r-- | tools/telemetry/telemetry/core/chrome/cros_interface.py | 19 |
2 files changed, 40 insertions, 11 deletions
diff --git a/tools/telemetry/telemetry/core/chrome/cros_browser_backend.py b/tools/telemetry/telemetry/core/chrome/cros_browser_backend.py index 70400e7..8650f52 100644 --- a/tools/telemetry/telemetry/core/chrome/cros_browser_backend.py +++ b/tools/telemetry/telemetry/core/chrome/cros_browser_backend.py @@ -146,12 +146,40 @@ class CrOSBrowserBackend(browser_backend.BrowserBackend): return args + + def _GetSessionManagerPid(self, procs): + """Returns the pid of the session_manager process, given the list of + processes.""" + for pid, process, _ in procs: + if process.startswith('/sbin/session_manager '): + return pid + return None + @property def pid(self): - for pid, process in self._cri.ListProcesses(): + """Locates the pid of the main chrome browser process. + + Chrome on cros is usually in /opt/google/chrome, but could be in + /usr/local/ for developer workflows - debug chrome is too large to fit on + rootfs. + + Chrome spawns multiple processes for renderers. pids wrap around after they + are exhausted so looking for the smallest pid is not always correct. We + locate the session_manager's pid, and look for the chrome process that's an + immediate child. This is the main browser process. + """ + procs = self._cri.ListProcesses() + session_manager_pid = self._GetSessionManagerPid(procs) + if not session_manager_pid: + return None + + # Find the chrome process that is the child of the session_manager. + for pid, process, ppid in procs: + if ppid != session_manager_pid: + continue for path in self.CHROME_PATHS: if process.startswith(path): - return int(pid) + return pid return None @property diff --git a/tools/telemetry/telemetry/core/chrome/cros_interface.py b/tools/telemetry/telemetry/core/chrome/cros_interface.py index 3207f5c..243dfca 100644 --- a/tools/telemetry/telemetry/core/chrome/cros_interface.py +++ b/tools/telemetry/telemetry/core/chrome/cros_interface.py @@ -236,18 +236,19 @@ class CrOSInterface(object): return res def ListProcesses(self): + """Returns a tuple (pid, cmd, ppid) of all processes on the device.""" stdout, stderr = self.RunCmdOnDevice([ '/bin/ps', '--no-headers', '-A', - '-o', 'pid,args'], quiet=True) - assert stderr == '' + '-o', 'pid,ppid,args'], quiet=True) + assert stderr == '', stderr procs = [] for l in stdout.split('\n'): # pylint: disable=E1103 if l == '': continue - m = re.match('^\s*(\d+)\s+(.+)', l, re.DOTALL) + m = re.match('^\s*(\d+)\s+(\d+)\s+(.+)', l, re.DOTALL) assert m - procs.append(m.groups()) + procs.append((int(m.group(1)), m.group(3), int(m.group(2)))) logging.debug("ListProcesses(<predicate>)->[%i processes]" % len(procs)) return procs @@ -257,10 +258,10 @@ class CrOSInterface(object): def KillAllMatching(self, predicate): kills = ['kill', '-KILL'] - for p in self.ListProcesses(): - if predicate(p[1]): - logging.info('Killing %s', repr(p)) - kills.append(p[0]) + for pid, cmd, _ in self.ListProcesses(): + if predicate(cmd): + logging.info('Killing %s, pid %d' % cmd, pid) + kills.append(pid) logging.debug("KillAllMatching(<predicate>)->%i" % (len(kills) - 2)) if len(kills) > 2: self.RunCmdOnDevice(kills, quiet=True) @@ -269,7 +270,7 @@ class CrOSInterface(object): def IsServiceRunning(self, service_name): stdout, stderr = self.RunCmdOnDevice([ 'status', service_name], quiet=True) - assert stderr == '' + assert stderr == '', stderr running = 'running, process' in stdout logging.debug("IsServiceRunning(%s)->%s" % (service_name, running)) return running |