Commits

Aleksey Kunitskiy committed ef8b355

Updated to version 2.3

Comments (0)

Files changed (1)

 #                           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:
 #
     md5_new = md5.new
 
 if os.geteuid() != 0:
-    sys.stderr.write("For inspecting all processes, root permission required.\n");
+	sys.stderr.write("Warning: root permission is advisable.\n")
 
 split_args=False
 if len(sys.argv)==2 and sys.argv[1] == "--split-args":
 for cmd in cmds:
     cmd_count = count[cmd]
     if len(mem_ids[cmd]) == 1 and cmd_count > 1:
-        # Assume this program is using CLONE_CM without CLONE_THREAD
+        # Assume this program is using CLONE_VM without CLONE_THREAD
         # so only account for one of the processes
         cmds[cmd] /= cmd_count
         if have_pss:
     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
     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"
+        )