summaryrefslogtreecommitdiff
path: root/scripts/internal
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2019-02-25 02:35:07 -0800
committerGitHub <noreply@github.com>2019-02-25 02:35:07 -0800
commitf326539daa5bbd9153db79b508b6aaede731a154 (patch)
tree1b2b4c473155dae88dd8014259f802957509fad1 /scripts/internal
parent7a2572268168e96c8841ca83ab1a89735ec02c3a (diff)
downloadpsutil-f326539daa5bbd9153db79b508b6aaede731a154.tar.gz
Process SE DEBUG mode was not set on Windows (#1429)
Diffstat (limited to 'scripts/internal')
-rw-r--r--scripts/internal/procs_access_denied.py80
-rwxr-xr-xscripts/internal/winmake.py7
2 files changed, 87 insertions, 0 deletions
diff --git a/scripts/internal/procs_access_denied.py b/scripts/internal/procs_access_denied.py
new file mode 100644
index 00000000..9f792480
--- /dev/null
+++ b/scripts/internal/procs_access_denied.py
@@ -0,0 +1,80 @@
+#!/usr/bin/env python
+
+# Copyright (c) 2009, Giampaolo Rodola'. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""
+Helper script which tries to access all info of all running processes.
+It prints how many AccessDenied exceptions are raised in total and
+for each Process method.
+"""
+
+from __future__ import print_function, division
+from collections import defaultdict
+import sys
+
+import psutil
+
+
+def term_supports_colors(file=sys.stdout):
+ try:
+ import curses
+ assert file.isatty()
+ curses.setupterm()
+ assert curses.tigetnum("colors") > 0
+ except Exception:
+ return False
+ else:
+ return True
+
+
+COLORS = term_supports_colors()
+
+
+def hilite(s, ok=True, bold=False):
+ """Return an highlighted version of 'string'."""
+ if not COLORS:
+ return s
+ attr = []
+ if ok is None: # no color
+ pass
+ elif ok: # green
+ attr.append('32')
+ else: # red
+ attr.append('31')
+ if bold:
+ attr.append('1')
+ return '\x1b[%sm%s\x1b[0m' % (';'.join(attr), s)
+
+
+def main():
+ tot_procs = 0
+ tot_ads = 0
+ signaler = object()
+ d = defaultdict(int)
+ for p in psutil.process_iter(attrs=[], ad_value=signaler):
+ tot_procs += 1
+ for methname, value in p.info.items():
+ if value is signaler:
+ tot_ads += 1
+ d[methname] += 1
+ else:
+ d[methname] += 0
+
+ for methname, ads in sorted(d.items(), key=lambda x: x[1]):
+ perc = (ads / tot_procs) * 100
+ s = "%-20s %-3s %5.1f%% " % (methname, ads, perc)
+ if not ads:
+ s += "SUCCESS"
+ s = hilite(s, ok=True)
+ else:
+ s += "ACCESS DENIED"
+ s = hilite(s, ok=False)
+ print(s)
+ print("--------------------------")
+ print("total: %19s (%s total processes)" % (tot_ads, tot_procs))
+
+
+if __name__ == '__main__':
+ main()
diff --git a/scripts/internal/winmake.py b/scripts/internal/winmake.py
index b1ce7b8a..49aae699 100755
--- a/scripts/internal/winmake.py
+++ b/scripts/internal/winmake.py
@@ -483,6 +483,13 @@ def bench_oneshot_2():
sh("%s -Wa scripts\\internal\\bench_oneshot_2.py" % PYTHON)
+@cmd
+def print_access_denied():
+ """Benchmarks for oneshot() ctx manager (see #799)."""
+ install()
+ sh("%s -Wa scripts\\internal\\procs_access_denied.py" % PYTHON)
+
+
def set_python(s):
global PYTHON
if os.path.isabs(s):