summaryrefslogtreecommitdiffstats
path: root/ps_mem.py
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xssn.at>2010-10-27 16:17:11 +0200
committerFlorian Pritz <bluewind@xssn.at>2010-10-30 21:37:22 +0200
commit2899e54143edb9f4213e3ff8d366c0ef4897e01b (patch)
treec41017ea032593ed939192cf9020d42a95242c3c /ps_mem.py
parentac4624cd9bf1faf29cff2b04654bac9cbec03f48 (diff)
downloadbin-2899e54143edb9f4213e3ff8d366c0ef4897e01b.tar.gz
bin-2899e54143edb9f4213e3ff8d366c0ef4897e01b.tar.xz
ps_mem.py: upstream update
Signed-off-by: Florian Pritz <bluewind@xssn.at>
Diffstat (limited to 'ps_mem.py')
-rwxr-xr-xps_mem.py77
1 files changed, 35 insertions, 42 deletions
diff --git a/ps_mem.py b/ps_mem.py
index 88fa82a..c0b55a9 100755
--- a/ps_mem.py
+++ b/ps_mem.py
@@ -35,18 +35,8 @@
# Patch from patrice.bouchand.fedora@gmail.com
# V1.9 20 Feb 2008 Fix invalid values reported when PSS is available.
# Reported by Andrey Borzenkov <arvidjaar@mail.ru>
-# V2.0 15 Jan 2010 From a report by Brock Noland <brockn@gmail.com>
-# about overreporting of RAM usage of his java progs,
-# handle linux clones that have pids. I.E. that have
-# CLONE_VM specified without CLONE_THREAD.
-# V2.1 20 Jan 2010 Append [deleted] or [updated] to programs which are
-# no longer on disk or have a new version available.
-# Add a --split-args option to group programs based
-# on the full command line, which could be used
-# to monitor separate "pmon" processes for example:
-# ps_mem.py | grep [p]mon
-# V2.2 16 Feb 2010 Support python 3.
-# Patch from Brian Harring <ferringb@gmail.com>
+# V2.3 24 Sep 2010
+# http://github.com/pixelb/scripts/commits/master/scripts/ps_mem.py
# Notes:
#
@@ -91,7 +81,8 @@ except ImportError:
if os.geteuid() != 0:
sys.stderr.write("Sorry, root permission required.\n");
- sys.exit(1)
+ if __name__ == '__main__':
+ sys.exit(1)
split_args=False
if len(sys.argv)==2 and sys.argv[1] == "--split-args":
@@ -252,15 +243,16 @@ def cmd_with_count(cmd, count):
else:
return cmd
-sys.stdout.write(" Private + Shared = RAM used\tProgram \n\n")
-for cmd in sort_list:
- sys.stdout.write("%8sB + %8sB = %8sB\t%s\n" % (human(cmd[1]-shareds[cmd[0]]),
- human(shareds[cmd[0]]), human(cmd[1]),
- cmd_with_count(cmd[0], count[cmd[0]])))
-if have_pss:
- sys.stdout.write("%s\n%s%8sB\n%s\n" % ("-" * 33,
- " " * 24, human(total), "=" * 33))
-sys.stdout.write("\n Private + Shared = RAM used\tProgram \n\n")
+if __name__ == '__main__':
+ sys.stdout.write(" Private + Shared = RAM used\tProgram \n\n")
+ for cmd in sort_list:
+ sys.stdout.write("%8sB + %8sB = %8sB\t%s\n" % (human(cmd[1]-shareds[cmd[0]]),
+ human(shareds[cmd[0]]), human(cmd[1]),
+ cmd_with_count(cmd[0], count[cmd[0]])))
+ if have_pss:
+ sys.stdout.write("%s\n%s%8sB\n%s\n" % ("-" * 33,
+ " " * 24, human(total), "=" * 33))
+ sys.stdout.write("\n Private + Shared = RAM used\tProgram \n\n")
#Warn of possible inaccuracies
#2 = accurate & can total
@@ -285,23 +277,24 @@ def shared_val_accuracy():
else:
return 1
-vm_accuracy = shared_val_accuracy()
-if vm_accuracy == -1:
- sys.stderr.write(
- "Warning: Shared memory is not reported by this system.\n"
- )
- sys.stderr.write(
- "Values reported will be too large, and totals are not reported\n"
- )
-elif vm_accuracy == 0:
- sys.stderr.write(
- "Warning: Shared memory is not reported accurately by this system.\n"
- )
- sys.stderr.write(
- "Values reported could be too large, and totals are not reported\n"
- )
-elif vm_accuracy == 1:
- sys.stderr.write(
- "Warning: Shared memory is slightly over-estimated by this system\n"
- "for each program, so totals are not reported.\n"
- )
+if __name__ == '__main__':
+ vm_accuracy = shared_val_accuracy()
+ if vm_accuracy == -1:
+ sys.stderr.write(
+ "Warning: Shared memory is not reported by this system.\n"
+ )
+ sys.stderr.write(
+ "Values reported will be too large, and totals are not reported\n"
+ )
+ elif vm_accuracy == 0:
+ sys.stderr.write(
+ "Warning: Shared memory is not reported accurately by this system.\n"
+ )
+ sys.stderr.write(
+ "Values reported could be too large, and totals are not reported\n"
+ )
+ elif vm_accuracy == 1:
+ sys.stderr.write(
+ "Warning: Shared memory is slightly over-estimated by this system\n"
+ "for each program, so totals are not reported.\n"
+ )