From 2899e54143edb9f4213e3ff8d366c0ef4897e01b Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Wed, 27 Oct 2010 16:17:11 +0200 Subject: ps_mem.py: upstream update Signed-off-by: Florian Pritz --- ps_mem.py | 77 +++++++++++++++++++++++++++++---------------------------------- 1 file changed, 35 insertions(+), 42 deletions(-) (limited to 'ps_mem.py') 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 -# V2.0 15 Jan 2010 From a report by Brock Noland -# 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 +# 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" + ) -- cgit v1.2.3-24-g4f1b