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: A clone of 'free' cmdline utility. michael@0: """ michael@0: michael@0: import psutil michael@0: from psutil._compat import print_ michael@0: michael@0: def main(): michael@0: virt = psutil.virtual_memory() michael@0: swap = psutil.swap_memory() michael@0: templ = "%-7s %10s %10s %10s %10s %10s %10s" michael@0: print_(templ % ('', 'total', 'used', 'free', 'shared', 'buffers', 'cache')) michael@0: print_(templ % ('Mem:', int(virt.total / 1024), michael@0: int(virt.used / 1024), michael@0: int(virt.free / 1024), michael@0: int(getattr(virt, 'shared', 0) / 1024), michael@0: int(getattr(virt, 'buffers', 0) / 1024), michael@0: int(getattr(virt, 'cached', 0) / 1024))) michael@0: print_(templ % ('Swap:', int(swap.total / 1024), michael@0: int(swap.used / 1024), michael@0: int(swap.free / 1024), michael@0: '', '', '')) michael@0: michael@0: if __name__ == '__main__': michael@0: main()