python/psutil/examples/meminfo.py

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rwxr-xr-x

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 #!/usr/bin/env python
     3 # Copyright (c) 2009, Giampaolo Rodola'. All rights reserved.
     4 # Use of this source code is governed by a BSD-style license that can be
     5 # found in the LICENSE file.
     7 """
     8 Print system memory information.
     9 """
    11 import psutil
    12 from psutil._compat import print_
    14 def to_meg(n):
    15     return str(int(n / 1024 / 1024)) + "M"
    17 def pprint_ntuple(nt):
    18     for name in nt._fields:
    19         value = getattr(nt, name)
    20         if name != 'percent':
    21             value = to_meg(value)
    22         print_('%-10s : %7s' % (name.capitalize(), value))
    24 def main():
    25     print_('MEMORY\n------')
    26     pprint_ntuple(psutil.virtual_memory())
    27     print_('\nSWAP\n----')
    28     pprint_ntuple(psutil.swap_memory())
    30 if __name__ == '__main__':
    31     main()

mercurial