summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authornednguyen <nednguyen@google.com>2015-10-02 09:13:27 -0700
committerCommit bot <commit-bot@chromium.org>2015-10-02 16:14:13 +0000
commitd8144e08c7d01ae12fe6e585372877246ab60050 (patch)
treeac2c99dd3b530db8128cea711e2c233d4b088d08 /tools
parentf2d4bc0b958ae5a8eb2f1cc1abf56036fdca8aa8 (diff)
downloadchromium_src-d8144e08c7d01ae12fe6e585372877246ab60050.zip
chromium_src-d8144e08c7d01ae12fe6e585372877246ab60050.tar.gz
chromium_src-d8144e08c7d01ae12fe6e585372877246ab60050.tar.bz2
Try listing out all the subprocesses created by telemetry at the end.
BUG=536862 Review URL: https://codereview.chromium.org/1378563003 Cr-Commit-Position: refs/heads/master@{#352047}
Diffstat (limited to 'tools')
-rw-r--r--tools/telemetry/telemetry/internal/util/global_hooks.py36
1 files changed, 34 insertions, 2 deletions
diff --git a/tools/telemetry/telemetry/internal/util/global_hooks.py b/tools/telemetry/telemetry/internal/util/global_hooks.py
index b1541e9..8fe80d0 100644
--- a/tools/telemetry/telemetry/internal/util/global_hooks.py
+++ b/tools/telemetry/telemetry/internal/util/global_hooks.py
@@ -3,9 +3,11 @@
# found in the LICENSE file.
"""Hooks that apply globally to all scripts that import or use Telemetry."""
-
+import atexit
+import os
import signal
import sys
+import logging
from telemetry.internal.util import exception_formatter
@@ -14,7 +16,7 @@ def InstallHooks():
InstallUnhandledExceptionFormatter()
InstallStackDumpOnSigusr1()
InstallTerminationHook()
-
+ InstallListStrayProcessesUponExitHook()
def InstallUnhandledExceptionFormatter():
"""Print prettier exceptions that also contain the stack frame's locals."""
@@ -40,3 +42,33 @@ def InstallTerminationHook():
exception_formatter.PrintFormattedFrame(stack_frame, exception_string)
sys.exit(-1)
signal.signal(signal.SIGTERM, PrintStackAndExit)
+
+
+def InstallListStrayProcessesUponExitHook():
+ def _ListAllSubprocesses():
+ try:
+ import psutil
+ except ImportError:
+ logging.error(
+ 'psutil is not installed on the system. Not listing possible '
+ 'leaked processes. To install psutil, see: '
+ 'https://pypi.python.org/pypi/psutil')
+ telemetry_pid = os.getpid()
+ parent = psutil.Process(telemetry_pid)
+ if hasattr(parent, 'children'):
+ children = parent.children(recursive=True)
+ else: # Some old version of psutil use get_children instead children.
+ children = parent.get_children()
+ if children:
+ leak_processes_info = []
+ for p in children:
+ process_info = '%s (%s)' % (p.name(), p.pid)
+ try:
+ process_info += ' - %s' % p.cmdline()
+ except Exception:
+ pass
+ leak_processes_info.append(process_info)
+ logging.error('Telemetry leaks these processes: %s',
+ ', '.join(leak_processes_info))
+
+ atexit.register(_ListAllSubprocesses)