summaryrefslogtreecommitdiff
path: root/scripts/internal/print_access_denied.py
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2020-01-16 11:12:31 +0100
committerGiampaolo Rodola <g.rodola@gmail.com>2020-01-16 11:12:31 +0100
commit678292f90c6961a0d0fe9f5bd80f7fbde8f79e85 (patch)
treefeada50e667b7335cc9b257b5fd0a5ef4b346eb3 /scripts/internal/print_access_denied.py
parentefaa9e0169e790310e19cea1c4d8389395387c0d (diff)
downloadpsutil-678292f90c6961a0d0fe9f5bd80f7fbde8f79e85.tar.gz
AD script: print AD percentage + elapsed time
Diffstat (limited to 'scripts/internal/print_access_denied.py')
-rw-r--r--scripts/internal/print_access_denied.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/scripts/internal/print_access_denied.py b/scripts/internal/print_access_denied.py
index 1519c94b..b94e6e00 100644
--- a/scripts/internal/print_access_denied.py
+++ b/scripts/internal/print_access_denied.py
@@ -47,6 +47,7 @@ Totals: access-denied=1744, calls=10020, processes=334
from __future__ import print_function, division
from collections import defaultdict
+import time
import psutil
from scriptutils import hilite
@@ -59,6 +60,7 @@ def main():
tot_calls = 0
signaler = object()
d = defaultdict(int)
+ start = time.time()
for p in psutil.process_iter(attrs=[], ad_value=signaler):
tot_procs += 1
for methname, value in p.info.items():
@@ -68,6 +70,7 @@ def main():
d[methname] += 1
else:
d[methname] += 0
+ elapsed = time.time() - start
# print
templ = "%-20s %-5s %-9s %s"
@@ -79,9 +82,11 @@ def main():
s = templ % (methname, ads, "%6.1f%%" % perc, outcome)
s = hilite(s, ok=not ads)
print(s)
+ tot_perc = round((tot_ads / tot_calls) * 100, 1)
print("-" * 50)
- print("Totals: access-denied=%s, calls=%s, processes=%s" % (
- tot_ads, tot_calls, tot_procs))
+ print("Totals: access-denied=%s (%s%%), calls=%s, processes=%s, "
+ "elapsed=%ss" % (tot_ads, tot_perc, tot_calls, tot_procs,
+ round(elapsed, 2)))
if __name__ == '__main__':