michael@0: #!/usr/bin/env python michael@0: michael@0: # Copyright (c) 2009, Giampaolo Rodola'. All rights reserved. michael@0: # Use of this source code is governed by a BSD-style license that can be michael@0: # found in the LICENSE file. michael@0: michael@0: """ michael@0: Print system memory information. michael@0: """ michael@0: michael@0: import psutil michael@0: from psutil._compat import print_ michael@0: michael@0: def to_meg(n): michael@0: return str(int(n / 1024 / 1024)) + "M" michael@0: michael@0: def pprint_ntuple(nt): michael@0: for name in nt._fields: michael@0: value = getattr(nt, name) michael@0: if name != 'percent': michael@0: value = to_meg(value) michael@0: print_('%-10s : %7s' % (name.capitalize(), value)) michael@0: michael@0: def main(): michael@0: print_('MEMORY\n------') michael@0: pprint_ntuple(psutil.virtual_memory()) michael@0: print_('\nSWAP\n----') michael@0: pprint_ntuple(psutil.swap_memory()) michael@0: michael@0: if __name__ == '__main__': michael@0: main()