Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | #!/usr/bin/env python |
michael@0 | 2 | |
michael@0 | 3 | # Copyright (c) 2009, Giampaolo Rodola'. All rights reserved. |
michael@0 | 4 | # Use of this source code is governed by a BSD-style license that can be |
michael@0 | 5 | # found in the LICENSE file. |
michael@0 | 6 | |
michael@0 | 7 | """ |
michael@0 | 8 | Print system memory information. |
michael@0 | 9 | """ |
michael@0 | 10 | |
michael@0 | 11 | import psutil |
michael@0 | 12 | from psutil._compat import print_ |
michael@0 | 13 | |
michael@0 | 14 | def to_meg(n): |
michael@0 | 15 | return str(int(n / 1024 / 1024)) + "M" |
michael@0 | 16 | |
michael@0 | 17 | def pprint_ntuple(nt): |
michael@0 | 18 | for name in nt._fields: |
michael@0 | 19 | value = getattr(nt, name) |
michael@0 | 20 | if name != 'percent': |
michael@0 | 21 | value = to_meg(value) |
michael@0 | 22 | print_('%-10s : %7s' % (name.capitalize(), value)) |
michael@0 | 23 | |
michael@0 | 24 | def main(): |
michael@0 | 25 | print_('MEMORY\n------') |
michael@0 | 26 | pprint_ntuple(psutil.virtual_memory()) |
michael@0 | 27 | print_('\nSWAP\n----') |
michael@0 | 28 | pprint_ntuple(psutil.swap_memory()) |
michael@0 | 29 | |
michael@0 | 30 | if __name__ == '__main__': |
michael@0 | 31 | main() |