def virtual_memory():
 missing_fields = []
 mems = {}
 with open_binary(('%s/meminfo' % get_procfs_path())) as f:
  for line in f:
   fields = line.split()
   mems[fields[0]] = (int(fields[1]) * 1024)
 total = mems['MemTotal:']
 free = mems['MemFree:']
 buffers = mems['Buffers:']
 try:
  cached = mems['Cached:']
 except KeyError:
  cached = 0
  missing_fields.append('cached')
 else:
  cached += mems.get('SReclaimable:', 0)
 try:
  shared = mems['Shmem:']
 except KeyError:
  try:
   shared = mems['MemShared:']
  except KeyError:
   shared = 0
   missing_fields.append('shared')
 try:
  active = mems['Active:']
 except KeyError:
  active = 0
  missing_fields.append('active')
 try:
  inactive = mems['Inactive:']
 except KeyError:
  try:
   inactive = ((mems['Inact_dirty:'] + mems['Inact_clean:']) + mems['Inact_laundry:'])
  except KeyError:
   inactive = 0
   missing_fields.append('inactive')
 used = (((total - free) - cached) - buffers)
 if (used < 0):
  used = (total - free)
 try:
  avail = mems['MemAvailable:']
 except KeyError:
  avail = calculate_avail_vmem(mems)
 if (avail < 0):
  avail = 0
  missing_fields.append('available')
 if (avail > total):
  avail = free
 percent = usage_percent((total - avail), total, _round=1)
 if missing_fields:
  msg = ("%s memory stats couldn't be determined and %s set to 0" % (', '.join(missing_fields), ('was' if (len(missing_fields) == 1) else 'were')))
  warnings.warn(msg, RuntimeWarning)
 return svmem(total, avail, percent, used, free, active, inactive, buffers, cached, shared)

def virtual_memory ( ) : missing_fields = [ ] mems = { } with open_binary ( ( '%s/meminfo' % get_procfs_path ( ) ) ) as f : for line in f : fields = line . split ( ) mems [ fields [ 0 ] ] = ( int ( fields [ 1 ] ) * 1024 ) total = mems [ 'MemTotal:' ] free = mems [ 'MemFree:' ] buffers = mems [ 'Buffers:' ] try : cached = mems [ 'Cached:' ] except KeyError : cached = 0 missing_fields . append ( 'cached' ) else : cached += mems . get ( 'SReclaimable:' , 0 ) try : shared = mems [ 'Shmem:' ] except KeyError : try : shared = mems [ 'MemShared:' ] except KeyError : shared = 0 missing_fields . append ( 'shared' ) try : active = mems [ 'Active:' ] except KeyError : active = 0 missing_fields . append ( 'active' ) try : inactive = mems [ 'Inactive:' ] except KeyError : try : inactive = ( ( mems [ 'Inact_dirty:' ] + mems [ 'Inact_clean:' ] ) + mems [ 'Inact_laundry:' ] ) except KeyError : inactive = 0 missing_fields . append ( 'inactive' ) used = ( ( ( total - free ) - cached ) - buffers ) if ( used < 0 ) : used = ( total - free ) try : avail = mems [ 'MemAvailable:' ] except KeyError : avail = calculate_avail_vmem ( mems ) if ( avail < 0 ) : avail = 0 missing_fields . append ( 'available' ) if ( avail > total ) : avail = free percent = usage_percent ( ( total - avail ) , total , _round = 1 ) if missing_fields : msg = ( "%s memory stats couldn't be determined and %s set to 0" % ( ', ' . join ( missing_fields ) , ( 'was' if ( len ( missing_fields ) == 1 ) else 'were' ) ) ) warnings . warn ( msg , RuntimeWarning ) return svmem ( total , avail , percent , used , free , active , inactive , buffers , cached , shared )
return statistics about system memory usage as a namedtuple including the following fields .