Index: tools/telemetry/telemetry/core/platform/__init__.py |
diff --git a/tools/telemetry/telemetry/core/platform/__init__.py b/tools/telemetry/telemetry/core/platform/__init__.py |
index 1f77028115aa46c6b82b776f908f1b417ed80333..3f95c39d5658d704a9d21196139f4db658cc5b37 100644 |
--- a/tools/telemetry/telemetry/core/platform/__init__.py |
+++ b/tools/telemetry/telemetry/core/platform/__init__.py |
@@ -326,3 +326,34 @@ class Platform(object): |
} |
""" |
return self._platform_backend.StopMonitoringPower() |
+ |
+ def IsProcessRunning(self, proc): |
+ """ Return True if given process from subprocess.Popen is running. """ |
+ return self._platform_backend.IsProcessRunning(proc) |
+ |
+ def StopProcess(self, proc): |
+ """Cooperatively shut down the given process from subprocess.Popen. |
+ |
+ Returns True if it is believed the attempt succeeded.""" |
+ assert self.IsProcessRunning(proc), 'Process is not running' |
+ if self._platform_backend.IsCooperativeShutdownSupported(): |
+ self._platform_backend.CooperativelyShutdown(proc) |
+ try: |
+ util.WaitFor(lambda: not self.IsProcessRunning(proc), timeout=5) |
+ return True |
+ except util.TimeoutException: |
+ return False |
+ else: |
+ return False |
+ |
+ def KillProcess(self, proc): |
+ """ Kill given process from subprocess.Popen forcefully. |
+ |
+ Returns True if it is believed the attempt succeeded.""" |
+ assert self.IsProcessRunning(proc), 'Process is not running' |
+ self._proc.kill() |
+ try: |
+ util.WaitFor(lambda: not self.IsProcessRunning(proc), timeout=5) |
+ return True |
+ except util.TimeoutException: |
+ assert False |