Calculate the total memory in the current service unit.
510574
def get_mem_total(self):
        """"""
        with open('/proc/meminfo') as meminfo_file:
            for line in meminfo_file:
                key, mem = line.split(':', 2)
                if key == 'MemTotal':
                    mtot, modifier = mem.strip().split(' ')
                    return '%s%s' % (mtot, modifier[0].upper())
1102656
private function _memory()
    {
        $pagesize = $this->_kstat('unix:0:seg_cache:slab_size');
        $this->sys->setMemTotal($this->_kstat('unix:0:system_pages:pagestotal') * $pagesize);
        $this->sys->setMemUsed($this->_kstat('unix:0:system_pages:pageslocked') * $pagesize);
        $this->sys->setMemFree($this->_kstat('unix:0:system_pages:pagesfree') * $pagesize);
        $dev = new DiskDevice();
        $dev->setName('SWAP');
        $dev->setFsType('swap');
        $dev->setMountPoint('SWAP');
        $dev->setTotal($this->_kstat('unix:0:vminfo:swap_avail') / 1024);
        $dev->setUsed($this->_kstat('unix:0:vminfo:swap_alloc') / 1024);
        $dev->setFree($this->_kstat('unix:0:vminfo:swap_free') / 1024);
        $this->sys->setSwapDevices($dev);
    }
1145590
public function memory_stats()
    {
        if ($this->host_os === 'WINDOWS') {
            $wmi = new \COM("winmgmts:\\\\.\\root\\cimv2");
            $os =  $wmi->ExecQuery("SELECT * FROM Win32_OperatingSystem");

            foreach ($os as $m) {
                $mem_total = $m->TotalVisibleMemorySize;
                $mem_free = $m->FreePhysicalMemory;
            }

            $prefMemory = $wmi->ExecQuery("SELECT * FROM Win32_PerfFormattedData_PerfOS_Memory");

            foreach ($prefMemory as $pm) {
                $mem_cache = $pm->CacheBytes/1024;
            }
            $mem_buff = 0;
        } else {
            $fh = fopen('/proc/meminfo', 'r');

            $mem_free = $mem_buff = $mem_cache = $mem_total = 0;

            while ($line = fgets($fh)) {
                $pieces = array();
                if (preg_match('/^MemTotal:\s+(\d+)\skB$/', $line, $pieces)) {
                    $mem_total = $pieces[1];
                }
                if (preg_match('/^MemFree:\s+(\d+)\skB$/', $line, $pieces)) {
                    $mem_free = $pieces[1];
                }
                if (preg_match('/^Buffers:\s+(\d+)\skB$/', $line, $pieces)) {
                    $mem_buff = $pieces[1];
                }
                if (preg_match('/^Cached:\s+(\d+)\skB$/', $line, $pieces)) {
                    $mem_cache = $pieces[1];
                    break;
                }
            }
            fclose($fh);
        }

        $result['used']  = round(($mem_total - ($mem_buff + $mem_cache + $mem_free)) * 100 / $mem_total);
        $result['cache'] = round(($mem_cache + $mem_buff) * 100 / $mem_total);
        $result['free']  = round($mem_free * 100 / $mem_total);
        return $result;
    }
1001662
def memory_full():
    """"""
    current_process = psutil.Process(os.getpid())
    return (current_process.memory_percent() >
            config.MAXIMUM_CACHE_MEMORY_PERCENTAGE)
1211104
def _get_memory_base(gallery_conf):
    """"""
    if not gallery_conf['show_memory']:
        memory_base = 0
    else:
        # There might be a cleaner way to do this at some point
        from memory_profiler import memory_usage
        sleep, timeout = (1, 2) if sys.platform == 'win32' else (0.5, 1)
        proc = subprocess.Popen(
            [sys.executable, '-c',
             'import time, sys; time.sleep(%s); sys.exit(0)' % sleep],
            close_fds=True)
        memories = memory_usage(proc, interval=1e-3, timeout=timeout)
        kwargs = dict(timeout=timeout) if sys.version_info >= (3, 5) else {}
        proc.communicate(**kwargs)
        # On OSX sometimes the last entry can be None
        memories = [mem for mem in memories if mem is not None] + [0.]
        memory_base = max(memories)
    return memory_base
446123
def _memory_data(self, log_prefix):
        
        machine_data = psutil.virtual_memory()

        process = psutil.Process()
        process_data = {
            'memory_info': process.get_memory_info(),
            'ext_memory_info': process.get_ext_memory_info(),
            'memory_percent': process.get_memory_percent(),
            'cpu_percent': process.get_cpu_percent(),
        }

        log.info(u"%s Machine memory usage: %s; Process memory usage: %s", log_prefix, machine_data, process_data)
        return {
            'machine_data': machine_data,
            'process_data': process_data,
        }
1188909
def _mem(self):
        """"""
        value = int(psutil.virtual_memory().percent)
        set_metric("memory", value, category=self.category)
        gauge("memory", value)
14926
def calculate_size(name, service_name):
    
    data_size = 0
    data_size += calculate_size_str(name)
    data_size += calculate_size_str(service_name)
    return data_size
622753
def memory(self):
        
        class GpuMemoryInfo(Structure):
            _fields_ = [
                ('total', c_ulonglong),
                ('free', c_ulonglong),
                ('used', c_ulonglong),
            ]

        c_memory = GpuMemoryInfo()
        _check_return(_NVML.get_function(
            "nvmlDeviceGetMemoryInfo")(self.hnd, byref(c_memory)))
        return {'total': c_memory.total, 'free': c_memory.free, 'used': c_memory.used}
907192
def get_memory_usage(self, variables = None):
        
        result = dict(
            total_nb_bytes = 0,
            by_variable = {}
            )
        for entity in self.populations.values():
            entity_memory_usage = entity.get_memory_usage(variables = variables)
            result['total_nb_bytes'] += entity_memory_usage['total_nb_bytes']
            result['by_variable'].update(entity_memory_usage['by_variable'])
        return result
7844
def GetUsedMemory(self):
    
    try:
      memory_info = self._process.memory_info()
    except psutil.NoSuchProcess:
      return None

    # Psutil will return different memory information depending on what is
    # available in that platform.
    memory_data = getattr(memory_info, 'data', 0)
    memory_shared = getattr(memory_info, 'shared', 0)

    return memory_data + memory_shared
1111470
async def get_group_memory(self):
        """"""
        # Returns an XML with groupMemoryList
        act = self.service.action("X_GetAllGroupMemory")
        res = await act.async_call()
        return res
239503
def windows_memory_usage():
    """"""
    from ctypes import windll, Structure, c_uint64, sizeof, byref
    from ctypes.wintypes import DWORD
    class MemoryStatus(Structure):
        _fields_ = [('dwLength', DWORD),
                    ('dwMemoryLoad',DWORD),
                    ('ullTotalPhys', c_uint64),
                    ('ullAvailPhys', c_uint64),
                    ('ullTotalPageFile', c_uint64),
                    ('ullAvailPageFile', c_uint64),
                    ('ullTotalVirtual', c_uint64),
                    ('ullAvailVirtual', c_uint64),
                    ('ullAvailExtendedVirtual', c_uint64),]
    memorystatus = MemoryStatus()
    # MSDN documetation states that dwLength must be set to MemoryStatus
    # size before calling GlobalMemoryStatusEx
    # https://msdn.microsoft.com/en-us/library/aa366770(v=vs.85)
    memorystatus.dwLength = sizeof(memorystatus)
    windll.kernel32.GlobalMemoryStatusEx(byref(memorystatus))
    return float(memorystatus.dwMemoryLoad)
1306915
def memory(self):
        
        if self._memory is not None:
            return self._memory
        elif self._config is not None:
            return self._config.defaultMemory
        else:
            raise AttributeError("Default value for 'memory' cannot be determined")
514082
def calculate_current_allocation(self):
        
        for ac in self.asset_classes:
            ac.curr_alloc = ac.curr_value * 100 / self.total_amount
1141362
public static long getTotalPhysicalMemory() {
   long memory = -1;
   try {
     MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
     Object attribute = mBeanServer.getAttribute(new ObjectName("java.lang","type","OperatingSystem"), "TotalPhysicalMemorySize");
     return (Long) attribute;
   } catch (Throwable e) { e.printStackTrace(); }
   return memory;
 }
792944
public static systemmemory_stats get(nitro_service service) throws Exception{
		systemmemory_stats obj = new systemmemory_stats();
		systemmemory_stats[] response = (systemmemory_stats[])obj.stat_resources(service);
		return response[0];
	}