| Index: tools/telemetry/telemetry/core/backends/chrome/cros_interface.py
|
| diff --git a/tools/telemetry/telemetry/core/backends/chrome/cros_interface.py b/tools/telemetry/telemetry/core/backends/chrome/cros_interface.py
|
| index edc6f8db86c9d194e1d5b7aaf01ef4809ee184c5..d2f1517e9025ee16d8179daf450d786f768fd6df 100644
|
| --- a/tools/telemetry/telemetry/core/backends/chrome/cros_interface.py
|
| +++ b/tools/telemetry/telemetry/core/backends/chrome/cros_interface.py
|
| @@ -15,6 +15,12 @@ import tempfile
|
| # around pexpect, I suspect, if we wanted it to be faster. But, this was
|
| # convenient.
|
|
|
| +# Some developers' workflow includes running the Chrome process from
|
| +# /usr/local/... instead of the default location. We have to check for both
|
| +# paths in order to support this workflow.
|
| +_CHROME_PATHS = ['/opt/google/chrome/chrome ',
|
| + '/usr/local/opt/google/chrome/chrome ']
|
| +
|
| def IsRunningOnCrosDevice():
|
| """Returns True if we're on a ChromeOS device."""
|
| lsb_release = '/etc/lsb-release'
|
| @@ -287,6 +293,47 @@ class CrOSInterface(object):
|
| logging.debug("ListProcesses(<predicate>)->[%i processes]" % len(procs))
|
| return procs
|
|
|
| + 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
|
| +
|
| + def GetChromeProcess(self):
|
| + """Locates the 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.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 _CHROME_PATHS:
|
| + if process.startswith(path):
|
| + return {'pid': pid, 'path': path, 'args': process}
|
| + return None
|
| +
|
| + def GetChromePid(self):
|
| + """Returns pid of main chrome browser process."""
|
| + result = self.GetChromeProcess()
|
| + if result and 'pid' in result:
|
| + return result['pid']
|
| + return None
|
| +
|
| def RmRF(self, filename):
|
| logging.debug("rm -rf %s" % filename)
|
| self.RunCmdOnDevice(['rm', '-rf', filename], quiet=True)
|
|
|