Advertisement
Aisberg

ps_mem.py

Mar 30th, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 22.00 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. # Try to determine how much RAM is currently being used per program.
  4. # Note per _program_, not per process. So for example this script
  5. # will report RAM used by all httpd process together. In detail it reports:
  6. # sum(private RAM for program processes) + sum(Shared RAM for program processes)
  7. # The shared RAM is problematic to calculate, and this script automatically
  8. # selects the most accurate method available for your kernel.
  9.  
  10. # Licence: LGPLv2
  11. # Author:  P@draigBrady.com
  12. # Source:  http://www.pixelbeat.org/scripts/ps_mem.py
  13.  
  14. # V1.0      06 Jul 2005     Initial release
  15. # V1.1      11 Aug 2006     root permission required for accuracy
  16. # V1.2      08 Nov 2006     Add total to output
  17. #                           Use KiB,MiB,... for units rather than K,M,...
  18. # V1.3      22 Nov 2006     Ignore shared col from /proc/$pid/statm for
  19. #                           2.6 kernels up to and including 2.6.9.
  20. #                           There it represented the total file backed extent
  21. # V1.4      23 Nov 2006     Remove total from output as it's meaningless
  22. #                           (the shared values overlap with other programs).
  23. #                           Display the shared column. This extra info is
  24. #                           useful, especially as it overlaps between programs.
  25. # V1.5      26 Mar 2007     Remove redundant recursion from human()
  26. # V1.6      05 Jun 2007     Also report number of processes with a given name.
  27. #                           Patch from riccardo.murri@gmail.com
  28. # V1.7      20 Sep 2007     Use PSS from /proc/$pid/smaps if available, which
  29. #                           fixes some over-estimation and allows totalling.
  30. #                           Enumerate the PIDs directly rather than using ps,
  31. #                           which fixes the possible race between reading
  32. #                           RSS with ps, and shared memory with this program.
  33. #                           Also we can show non truncated command names.
  34. # V1.8      28 Sep 2007     More accurate matching for stats in /proc/$pid/smaps
  35. #                           as otherwise could match libraries causing a crash.
  36. #                           Patch from patrice.bouchand.fedora@gmail.com
  37. # V1.9      20 Feb 2008     Fix invalid values reported when PSS is available.
  38. #                           Reported by Andrey Borzenkov <arvidjaar@mail.ru>
  39. # V3.9      07 Mar 2017
  40. #   http://github.com/pixelb/scripts/commits/master/scripts/ps_mem.py
  41.  
  42. # Notes:
  43. #
  44. # All interpreted programs where the interpreter is started
  45. # by the shell or with env, will be merged to the interpreter
  46. # (as that's what's given to exec). For e.g. all python programs
  47. # starting with "#!/usr/bin/env python" will be grouped under python.
  48. # You can change this by using the full command line but that will
  49. # have the undesirable affect of splitting up programs started with
  50. # differing parameters (for e.g. mingetty tty[1-6]).
  51. #
  52. # For 2.6 kernels up to and including 2.6.13 and later 2.4 redhat kernels
  53. # (rmap vm without smaps) it can not be accurately determined how many pages
  54. # are shared between processes in general or within a program in our case:
  55. # http://lkml.org/lkml/2005/7/6/250
  56. # A warning is printed if overestimation is possible.
  57. # In addition for 2.6 kernels up to 2.6.9 inclusive, the shared
  58. # value in /proc/$pid/statm is the total file-backed extent of a process.
  59. # We ignore that, introducing more overestimation, again printing a warning.
  60. # Since kernel 2.6.23-rc8-mm1 PSS is available in smaps, which allows
  61. # us to calculate a more accurate value for the total RAM used by programs.
  62. #
  63. # Programs that use CLONE_VM without CLONE_THREAD are discounted by assuming
  64. # they're the only programs that have the same /proc/$PID/smaps file for
  65. # each instance.  This will fail if there are multiple real instances of a
  66. # program that then use CLONE_VM without CLONE_THREAD, or if a clone changes
  67. # its memory map while we're checksumming each /proc/$PID/smaps.
  68. #
  69. # I don't take account of memory allocated for a program
  70. # by other programs. For e.g. memory used in the X server for
  71. # a program could be determined, but is not.
  72. #
  73. # FreeBSD is supported if linprocfs is mounted at /compat/linux/proc/
  74. # FreeBSD 8.0 supports up to a level of Linux 2.6.16
  75.  
  76. import getopt
  77. import time
  78. import errno
  79. import os
  80. import sys
  81.  
  82. # The following exits cleanly on Ctrl-C or EPIPE
  83. # while treating other exceptions as before.
  84. def std_exceptions(etype, value, tb):
  85.     sys.excepthook = sys.__excepthook__
  86.     if issubclass(etype, KeyboardInterrupt):
  87.         pass
  88.     elif issubclass(etype, IOError) and value.errno == errno.EPIPE:
  89.         pass
  90.     else:
  91.         sys.__excepthook__(etype, value, tb)
  92. sys.excepthook = std_exceptions
  93.  
  94. #
  95. #   Define some global variables
  96. #
  97.  
  98. PAGESIZE = os.sysconf("SC_PAGE_SIZE") / 1024 #KiB
  99. our_pid = os.getpid()
  100.  
  101. have_pss = 0
  102. have_swap_pss = 0
  103.  
  104. class Proc:
  105.     def __init__(self):
  106.         uname = os.uname()
  107.         if uname[0] == "FreeBSD":
  108.             self.proc = '/compat/linux/proc'
  109.         else:
  110.             self.proc = '/proc'
  111.  
  112.     def path(self, *args):
  113.         return os.path.join(self.proc, *(str(a) for a in args))
  114.  
  115.     def open(self, *args):
  116.         try:
  117.             if sys.version_info < (3,):
  118.                 return open(self.path(*args))
  119.             else:
  120.                 return open(self.path(*args), errors='ignore')
  121.         except (IOError, OSError):
  122.             val = sys.exc_info()[1]
  123.             if (val.errno == errno.ENOENT or # kernel thread or process gone
  124.                 val.errno == errno.EPERM or
  125.                 val.errno == errno.EACCES):
  126.                 raise LookupError
  127.             raise
  128.  
  129. proc = Proc()
  130.  
  131.  
  132. #
  133. #   Functions
  134. #
  135.  
  136. def parse_options():
  137.     try:
  138.         long_options = [
  139.             'split-args',
  140.             'help',
  141.             'total',
  142.             'discriminate-by-pid',
  143.             'swap'
  144.         ]
  145.         opts, args = getopt.getopt(sys.argv[1:], "shtdSp:w:", long_options)
  146.     except getopt.GetoptError:
  147.         sys.stderr.write(help())
  148.         sys.exit(3)
  149.  
  150.     if len(args):
  151.         sys.stderr.write("Extraneous arguments: %s\n" % args)
  152.         sys.exit(3)
  153.  
  154.     # ps_mem.py options
  155.     split_args = False
  156.     pids_to_show = None
  157.     discriminate_by_pid = False
  158.     show_swap = False
  159.     watch = None
  160.     only_total = False
  161.  
  162.     for o, a in opts:
  163.         if o in ('-s', '--split-args'):
  164.             split_args = True
  165.         if o in ('-t', '--total'):
  166.             only_total = True
  167.         if o in ('-d', '--discriminate-by-pid'):
  168.             discriminate_by_pid = True
  169.         if o in ('-S', '--swap'):
  170.             show_swap = True
  171.         if o in ('-h', '--help'):
  172.             sys.stdout.write(help())
  173.             sys.exit(0)
  174.         if o in ('-p',):
  175.             try:
  176.                 pids_to_show = [int(x) for x in a.split(',')]
  177.             except:
  178.                 sys.stderr.write(help())
  179.                 sys.exit(3)
  180.         if o in ('-w',):
  181.             try:
  182.                 watch = int(a)
  183.             except:
  184.                 sys.stderr.write(help())
  185.                 sys.exit(3)
  186.  
  187.     return (
  188.         split_args,
  189.         pids_to_show,
  190.         watch,
  191.         only_total,
  192.         discriminate_by_pid,
  193.         show_swap
  194.     )
  195.  
  196.  
  197. def help():
  198.     help_msg = 'Usage: ps_mem [OPTION]...\n' \
  199.         'Show program core memory usage\n' \
  200.         '\n' \
  201.         '  -h, -help                   Show this help\n' \
  202.         '  -p <pid>[,pid2,...pidN]     Only show memory usage PIDs in the '\
  203.         'specified list\n' \
  204.         '  -s, --split-args            Show and separate by, all command line'\
  205.         ' arguments\n' \
  206.         '  -t, --total                 Show only the total value\n' \
  207.         '  -d, --discriminate-by-pid   Show by process rather than by program\n' \
  208.         '  -S, --swap                  Show swap information\n' \
  209.         '  -w <N>                      Measure and show process memory every'\
  210.         ' N seconds\n'
  211.  
  212.     return help_msg
  213.  
  214.  
  215. # (major,minor,release)
  216. def kernel_ver():
  217.     kv = proc.open('sys/kernel/osrelease').readline().split(".")[:3]
  218.     last = len(kv)
  219.     if last == 2:
  220.         kv.append('0')
  221.     last -= 1
  222.     while last > 0:
  223.         for char in "-_":
  224.             kv[last] = kv[last].split(char)[0]
  225.         try:
  226.             int(kv[last])
  227.         except:
  228.             kv[last] = 0
  229.         last -= 1
  230.     return (int(kv[0]), int(kv[1]), int(kv[2]))
  231.  
  232.  
  233. #return Private,Shared
  234. #Note shared is always a subset of rss (trs is not always)
  235. def getMemStats(pid):
  236.     global have_pss
  237.     global have_swap_pss
  238.     mem_id = pid #unique
  239.     Private_lines = []
  240.     Shared_lines = []
  241.     Pss_lines = []
  242.     Rss = (int(proc.open(pid, 'statm').readline().split()[1])
  243.            * PAGESIZE)
  244.     Swap_lines = []
  245.     Swap_pss_lines = []
  246.  
  247.     Swap = 0
  248.     Swap_pss = 0
  249.  
  250.     if os.path.exists(proc.path(pid, 'smaps')):  # stat
  251.         lines = proc.open(pid, 'smaps').readlines()  # open
  252.         # Note we checksum smaps as maps is usually but
  253.         # not always different for separate processes.
  254.         mem_id = hash(''.join(lines))
  255.         for line in lines:
  256.             if line.startswith("Shared"):
  257.                 Shared_lines.append(line)
  258.             elif line.startswith("Private"):
  259.                 Private_lines.append(line)
  260.             elif line.startswith("Pss"):
  261.                 have_pss = 1
  262.                 Pss_lines.append(line)
  263.             elif line.startswith("Swap:"):
  264.                 Swap_lines.append(line)
  265.             elif line.startswith("SwapPss:"):
  266.                 have_swap_pss = 1
  267.                 Swap_pss_lines.append(line)
  268.         Shared = sum([int(line.split()[1]) for line in Shared_lines])
  269.         Private = sum([int(line.split()[1]) for line in Private_lines])
  270.         #Note Shared + Private = Rss above
  271.         #The Rss in smaps includes video card mem etc.
  272.         if have_pss:
  273.             pss_adjust = 0.5 # add 0.5KiB as this avg error due to truncation
  274.             Pss = sum([float(line.split()[1])+pss_adjust for line in Pss_lines])
  275.             Shared = Pss - Private
  276.         # Note that Swap = Private swap + Shared swap.
  277.         Swap = sum([int(line.split()[1]) for line in Swap_lines])
  278.         if have_swap_pss:
  279.             # The kernel supports SwapPss, that shows proportional swap share.
  280.             # Note that Swap - SwapPss is not Private Swap.
  281.             Swap_pss = sum([int(line.split()[1]) for line in Swap_pss_lines])
  282.     elif (2,6,1) <= kernel_ver() <= (2,6,9):
  283.         Shared = 0 #lots of overestimation, but what can we do?
  284.         Private = Rss
  285.     else:
  286.         Shared = int(proc.open(pid, 'statm').readline().split()[2])
  287.         Shared *= PAGESIZE
  288.         Private = Rss - Shared
  289.     return (Private, Shared, mem_id, Swap, Swap_pss)
  290.  
  291.  
  292. def getCmdName(pid, split_args, discriminate_by_pid):
  293.     cmdline = proc.open(pid, 'cmdline').read().split("\0")
  294.     if cmdline[-1] == '' and len(cmdline) > 1:
  295.         cmdline = cmdline[:-1]
  296.  
  297.     path = proc.path(pid, 'exe')
  298.     try:
  299.         path = os.readlink(path)
  300.         # Some symlink targets were seen to contain NULs on RHEL 5 at least
  301.         # https://github.com/pixelb/scripts/pull/10, so take string up to NUL
  302.         path = path.split('\0')[0]
  303.     except OSError:
  304.         val = sys.exc_info()[1]
  305.         if (val.errno == errno.ENOENT or # either kernel thread or process gone
  306.             val.errno == errno.EPERM or
  307.             val.errno == errno.EACCES):
  308.             raise LookupError
  309.         raise
  310.  
  311.     if split_args:
  312.         return ' '.join(cmdline).replace('\n', ' ')
  313.     if path.endswith(" (deleted)"):
  314.         path = path[:-10]
  315.         if os.path.exists(path):
  316.             path += " [updated]"
  317.         else:
  318.             #The path could be have prelink stuff so try cmdline
  319.             #which might have the full path present. This helped for:
  320.             #/usr/libexec/notification-area-applet.#prelink#.fX7LCT (deleted)
  321.             if os.path.exists(cmdline[0]):
  322.                 path = cmdline[0] + " [updated]"
  323.             else:
  324.                 path += " [deleted]"
  325.     exe = os.path.basename(path)
  326.     cmd = proc.open(pid, 'status').readline()[6:-1]
  327.     if exe.startswith(cmd):
  328.         cmd = exe #show non truncated version
  329.         #Note because we show the non truncated name
  330.         #one can have separated programs as follows:
  331.         #584.0 KiB +   1.0 MiB =   1.6 MiB    mozilla-thunder (exe -> bash)
  332.         # 56.0 MiB +  22.2 MiB =  78.2 MiB    mozilla-thunderbird-bin
  333.     if sys.version_info >= (3,):
  334.         cmd = cmd.encode(errors='replace').decode()
  335.     if discriminate_by_pid:
  336.         cmd = '%s [%d]' % (cmd, pid)
  337.     return cmd
  338.  
  339.  
  340. #The following matches "du -h" output
  341. #see also human.py
  342. def human(num, power="Ki", units=None):
  343.     if units is None:
  344.         powers = ["Ki", "Mi", "Gi", "Ti"]
  345.         while num >= 1000: #4 digits
  346.             num /= 1024.0
  347.             power = powers[powers.index(power)+1]
  348.         return "%.1f %sB" % (num, power)
  349.     else:
  350.         return "%.f" % ((num * 1024) / units)
  351.  
  352.  
  353. def cmd_with_count(cmd, count):
  354.     if count > 1:
  355.         return "%s (%u)" % (cmd, count)
  356.     else:
  357.         return cmd
  358.  
  359. #Warn of possible inaccuracies
  360. #2 = accurate & can total
  361. #1 = accurate only considering each process in isolation
  362. #0 = some shared mem not reported
  363. #-1= all shared mem not reported
  364. def shared_val_accuracy():
  365.     """http://wiki.apache.org/spamassassin/TopSharedMemoryBug"""
  366.     kv = kernel_ver()
  367.     pid = os.getpid()
  368.     if kv[:2] == (2,4):
  369.         if proc.open('meminfo').read().find("Inact_") == -1:
  370.             return 1
  371.         return 0
  372.     elif kv[:2] == (2,6):
  373.         if os.path.exists(proc.path(pid, 'smaps')):
  374.             if proc.open(pid, 'smaps').read().find("Pss:")!=-1:
  375.                 return 2
  376.             else:
  377.                 return 1
  378.         if (2,6,1) <= kv <= (2,6,9):
  379.             return -1
  380.         return 0
  381.     elif kv[0] > 2 and os.path.exists(proc.path(pid, 'smaps')):
  382.         return 2
  383.     else:
  384.         return 1
  385.  
  386. def show_shared_val_accuracy( possible_inacc, only_total=False ):
  387.     level = ("Warning","Error")[only_total]
  388.     if possible_inacc == -1:
  389.         sys.stderr.write(
  390.          "%s: Shared memory is not reported by this system.\n" % level
  391.         )
  392.         sys.stderr.write(
  393.          "Values reported will be too large, and totals are not reported\n"
  394.         )
  395.     elif possible_inacc == 0:
  396.         sys.stderr.write(
  397.          "%s: Shared memory is not reported accurately by this system.\n" % level
  398.         )
  399.         sys.stderr.write(
  400.          "Values reported could be too large, and totals are not reported\n"
  401.         )
  402.     elif possible_inacc == 1:
  403.         sys.stderr.write(
  404.          "%s: Shared memory is slightly over-estimated by this system\n"
  405.          "for each program, so totals are not reported.\n" % level
  406.         )
  407.     sys.stderr.close()
  408.     if only_total and possible_inacc != 2:
  409.         sys.exit(1)
  410.  
  411.  
  412. def get_memory_usage(pids_to_show, split_args, discriminate_by_pid,
  413.                      include_self=False, only_self=False):
  414.     cmds = {}
  415.     shareds = {}
  416.     mem_ids = {}
  417.     count = {}
  418.     swaps = {}
  419.     shared_swaps = {}
  420.     for pid in os.listdir(proc.path('')):
  421.         if not pid.isdigit():
  422.             continue
  423.         pid = int(pid)
  424.  
  425.         # Some filters
  426.         if only_self and pid != our_pid:
  427.             continue
  428.         if pid == our_pid and not include_self:
  429.             continue
  430.         if pids_to_show is not None and pid not in pids_to_show:
  431.             continue
  432.  
  433.         try:
  434.             cmd = getCmdName(pid, split_args, discriminate_by_pid)
  435.         except LookupError:
  436.             #operation not permitted
  437.             #kernel threads don't have exe links or
  438.             #process gone
  439.             continue
  440.  
  441.         try:
  442.             private, shared, mem_id, swap, swap_pss = getMemStats(pid)
  443.         except RuntimeError:
  444.             continue #process gone
  445.         if shareds.get(cmd):
  446.             if have_pss: #add shared portion of PSS together
  447.                 shareds[cmd] += shared
  448.             elif shareds[cmd] < shared: #just take largest shared val
  449.                 shareds[cmd] = shared
  450.         else:
  451.             shareds[cmd] = shared
  452.         cmds[cmd] = cmds.setdefault(cmd, 0) + private
  453.         if cmd in count:
  454.             count[cmd] += 1
  455.         else:
  456.             count[cmd] = 1
  457.         mem_ids.setdefault(cmd, {}).update({mem_id: None})
  458.  
  459.         # Swap (overcounting for now...)
  460.         swaps[cmd] = swaps.setdefault(cmd, 0) + swap
  461.         if have_swap_pss:
  462.             shared_swaps[cmd] = shared_swaps.setdefault(cmd, 0) + swap_pss
  463.         else:
  464.             shared_swaps[cmd] = 0
  465.  
  466.     # Total swaped mem for each program
  467.     total_swap = 0
  468.  
  469.     # Total swaped shared mem for each program
  470.     total_shared_swap = 0
  471.  
  472.     # Add shared mem for each program
  473.     total = 0
  474.  
  475.     for cmd in cmds:
  476.         cmd_count = count[cmd]
  477.         if len(mem_ids[cmd]) == 1 and cmd_count > 1:
  478.             # Assume this program is using CLONE_VM without CLONE_THREAD
  479.             # so only account for one of the processes
  480.             cmds[cmd] /= cmd_count
  481.             if have_pss:
  482.                 shareds[cmd] /= cmd_count
  483.         cmds[cmd] = cmds[cmd] + shareds[cmd]
  484.         total += cmds[cmd]  # valid if PSS available
  485.         total_swap += swaps[cmd]
  486.         if have_swap_pss:
  487.             total_shared_swap += shared_swaps[cmd]
  488.  
  489.     sorted_cmds = sorted(cmds.items(), key=lambda x:x[1])
  490.     sorted_cmds = [x for x in sorted_cmds if x[1]]
  491.  
  492.     return sorted_cmds, shareds, count, total, swaps, shared_swaps, \
  493.         total_swap, total_shared_swap
  494.  
  495.  
  496. def print_header(show_swap, discriminate_by_pid):
  497.     output_string = " Private  +   Shared  =  RAM used"
  498.     if show_swap:
  499.         if have_swap_pss:
  500.             output_string += " " * 5 + "Shared Swap"
  501.         output_string += "   Swap used"
  502.     output_string += "\tProgram"
  503.     if discriminate_by_pid:
  504.         output_string += "[pid]"
  505.     output_string += "\n\n"
  506.     sys.stdout.write(output_string)
  507.  
  508.  
  509. def print_memory_usage(sorted_cmds, shareds, count, total, swaps, total_swap,
  510.                        shared_swaps, total_shared_swap, show_swap):
  511.     for cmd in sorted_cmds:
  512.  
  513.         output_string = "%9s + %9s = %9s"
  514.         output_data = (human(cmd[1]-shareds[cmd[0]]),
  515.                        human(shareds[cmd[0]]), human(cmd[1]))
  516.         if show_swap:
  517.             if have_swap_pss:
  518.                 output_string += "\t%9s"
  519.                 output_data += (human(shared_swaps[cmd[0]]),)
  520.             output_string += "   %9s"
  521.             output_data += (human(swaps[cmd[0]]),)
  522.         output_string += "\t%s\n"
  523.         output_data += (cmd_with_count(cmd[0], count[cmd[0]]),)
  524.  
  525.         sys.stdout.write(output_string % output_data)
  526.  
  527.     if have_pss:
  528.         if show_swap:
  529.             if have_swap_pss:
  530.                 sys.stdout.write("%s\n%s%9s%s%9s%s%9s\n%s\n" %
  531.                                  ("-" * 61, " " * 24, human(total), " " * 7,
  532.                                   human(total_shared_swap), " " * 3,
  533.                                   human(total_swap), "=" * 61))
  534.             else:
  535.                 sys.stdout.write("%s\n%s%9s%s%9s\n%s\n" %
  536.                                  ("-" * 45, " " * 24, human(total), " " * 3,
  537.                                   human(total_swap), "=" * 45))
  538.         else:
  539.             sys.stdout.write("%s\n%s%9s\n%s\n" %
  540.                              ("-" * 33, " " * 24, human(total), "=" * 33))
  541.  
  542.  
  543. def verify_environment(pids_to_show):
  544.     if os.geteuid() != 0 and not pids_to_show:
  545.         sys.stderr.write("Sorry, root permission required, or specify pids with -p\n")
  546.         sys.stderr.close()
  547.         sys.exit(1)
  548.  
  549.     try:
  550.         kernel_ver()
  551.     except (IOError, OSError):
  552.         val = sys.exc_info()[1]
  553.         if val.errno == errno.ENOENT:
  554.             sys.stderr.write(
  555.               "Couldn't access " + proc.path('') + "\n"
  556.               "Only GNU/Linux and FreeBSD (with linprocfs) are supported\n")
  557.             sys.exit(2)
  558.         else:
  559.             raise
  560.  
  561. def main():
  562.     split_args, pids_to_show, watch, only_total, discriminate_by_pid, \
  563.     show_swap = parse_options()
  564.  
  565.     verify_environment(pids_to_show)
  566.  
  567.     if not only_total:
  568.         print_header(show_swap, discriminate_by_pid)
  569.  
  570.     if watch is not None:
  571.         try:
  572.             sorted_cmds = True
  573.             while sorted_cmds:
  574.                 sorted_cmds, shareds, count, total, swaps, shared_swaps, \
  575.                     total_swap, total_shared_swap = \
  576.                     get_memory_usage(pids_to_show, split_args,
  577.                                      discriminate_by_pid)
  578.                 if only_total and have_pss:
  579.                     sys.stdout.write(human(total, units=1)+'\n')
  580.                 elif not only_total:
  581.                     print_memory_usage(sorted_cmds, shareds, count, total,
  582.                                        swaps, total_swap, shared_swaps,
  583.                                        total_shared_swap, show_swap)
  584.  
  585.                 sys.stdout.flush()
  586.                 time.sleep(watch)
  587.             else:
  588.                 sys.stdout.write('Process does not exist anymore.\n')
  589.         except KeyboardInterrupt:
  590.             pass
  591.     else:
  592.         # This is the default behavior
  593.         sorted_cmds, shareds, count, total, swaps, shared_swaps, total_swap, \
  594.             total_shared_swap = get_memory_usage(pids_to_show, split_args,
  595.                                                  discriminate_by_pid)
  596.         if only_total and have_pss:
  597.             sys.stdout.write(human(total, units=1)+'\n')
  598.         elif not only_total:
  599.             print_memory_usage(sorted_cmds, shareds, count, total, swaps,
  600.                                total_swap, shared_swaps, total_shared_swap,
  601.                                show_swap)
  602.  
  603.     # We must close explicitly, so that any EPIPE exception
  604.     # is handled by our excepthook, rather than the default
  605.     # one which is reenabled after this script finishes.
  606.     sys.stdout.close()
  607.  
  608.     vm_accuracy = shared_val_accuracy()
  609.     show_shared_val_accuracy( vm_accuracy, only_total )
  610.  
  611. if __name__ == '__main__': main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement