Get peak memory usage for this process, as measured by
    max-resident-set size:

    https://unix.stackexchange.com/questions/30940/getrusage-system-call-what-is-maximum-resident-set-size

    Only works on OSX and Linux, returns 0.0 otherwise.
505133
def peak_memory_mb() -> float:
    
    if resource is None or sys.platform not in ('linux', 'darwin'):
        return 0.0

    # TODO(joelgrus): For whatever, our pinned version 0.521 of mypy does not like
    # next line, but later versions (e.g. 0.530) are fine with it. Once we get that
    # figured out, remove the type: ignore.
    peak = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss  # type: ignore

    if sys.platform == 'darwin':
        # On OSX the result is in bytes.
        return peak / 1_000_000

    else:
        # On Linux the result is in kilobytes.
        return peak / 1_000
1160275
public static function getMaxUploadSize()
    {
        $limit = false;
        if ($value = self::iniSizeToInt(ini_get('upload_max_filesize')))
        {
            $limit = $value;
        }

        $value = self::iniSizeToInt(ini_get('post_max_size'));
        $reserveForHeadersAndBody = 1024;
        if ($value && $value - $reserveForHeadersAndBody < $limit)
        {
            $limit = $value - $reserveForHeadersAndBody;
        }

        /*
        $value = self::iniValueToInt(ini_get('memory_limit'));
        $reserveForAppItself = memory_get_peak_usage(true);
        if ($value && $value < $limit)
        {
            $limit = $value - $reserveForAppItself;
        }
        */
        return $limit;
    }
1126413
def get_peak_mem():
    '''
    
    '''
    import resource
    rusage_denom = 1024.
    if sys.platform == 'darwin':
        # ... it seems that in OSX the output is different units ...
        rusage_denom = rusage_denom * rusage_denom
    mem = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss / rusage_denom
    return mem
782012
def get_free_memory():
    
    if 'win32' in sys.platform:
        # windows
        return get_free_memory_win()
    elif 'linux' in sys.platform:
        # linux
        return get_free_memory_linux()
    elif 'darwin' in sys.platform:
        # mac
        return get_free_memory_osx()
989880
def get_total_memory():
    """"""
    if platform.system() != "Linux":
        return None

    with open("/proc/meminfo", "r") as in_file:
        for line in in_file:
            info = line.split()
            if info[0] == "MemTotal:" and info[-1] == "kB":
                memory_mb = int(int(info[1]) / 1024)
                return memory_mb

    return None
127837
def memory():
    '''
    
    '''

    # test defaults
    # --memory-block-size = 10M
    # --memory-total-size = 1G

    # We test memory read / write against global / local scope of memory
    # Test data
    memory_oper = ['read', 'write']
    memory_scope = ['local', 'global']

    # Initializing the test variables
    test_command = 'sysbench --num-threads=64 --test=memory '
    test_command += '--memory-oper={0} --memory-scope={1} '
    test_command += '--memory-block-size=1K --memory-total-size=32G run '
    result = None
    ret_val = {}

    # Test begins!
    for oper in memory_oper:
        for scope in memory_scope:
            key = 'Operation: {0} Scope: {1}'.format(oper, scope)
            run_command = test_command.format(oper, scope)
            result = __salt__['cmd.run'](run_command)
            ret_val[key] = _parser(result)

    return ret_val
558156
def get_cpu_usage(user=None, ignore_self=True):
    
    pid = os.getpid()
    cmd = "ps aux"
    output = getoutput(cmd)
    total = 0
    largest_process = 0
    largest_process_name = None
    for row in output.split('\n')[1:]:
        row = row.split()
        if row[1] == str(pid) and ignore_self:
            continue
        if user is None or user == row[0]:
            cpu = decimal.Decimal(row[2])
            if cpu > total:
                largest_process = cpu
                largest_process_name = ' '.join(row[10:len(row)])
            total += decimal.Decimal(row[2])
    return total, largest_process, largest_process_name
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
207092
def get_host_usage(self):
        
        import psutil
        process_names = [proc.name for proc in psutil.process_iter()]
        cpu_pct = psutil.cpu_percent(interval=1)
        mem = psutil.virtual_memory()
        return str(cpu_pct), str(len(process_names)), str(mem.available), str(mem.total)
154165
def GetMemUsedMB(self):
        ''''''
        counter = c_uint()
        ret = vmGuestLib.VMGuestLib_GetMemUsedMB(self.handle.value, byref(counter))
        if ret != VMGUESTLIB_ERROR_SUCCESS: raise VMGuestLibException(ret)
        return counter.value
414613
private static long getSizeOfFreeMemory() {
		float fractionToUse = GlobalConfiguration.getFloat(
			ConfigConstants.TASK_MANAGER_MEMORY_FRACTION_KEY, ConfigConstants.DEFAULT_MEMORY_MANAGER_MEMORY_FRACTION);
		
		Runtime r = Runtime.getRuntime();
		long max = r.maxMemory();
		long total = r.totalMemory();
		long free = r.freeMemory();
		
		long available = max - total + free;
		return (long) (fractionToUse * available);
	}
1166703
public static double getSystemMemoryInfo() throws Exception {
        int total = 0;
        Process process = Runtime.getRuntime().exec("tasklist");
        String result = IOUtils.read(process.getInputStream(), Charset.defaultCharset().name());
        String[] results = result.split("\\n");
        for (String str : results) {
            Pattern pattern = Pattern.compile(".*\\s([0-9]{0,},[0-9]+)\\sK.*");
            Matcher matcher = pattern.matcher(str);
            if (matcher.find()) {
                String memorySizeStr = matcher.group(1).replace(",", "");
                int memorySize = Integer.parseInt(memorySizeStr);
                total += memorySize;
            }
        }
        return (double) total / 1024;
    }
567205
private static long getSizeOfPhysicalMemory() {
		switch (OperatingSystem.getCurrentOperatingSystem()) {
			case LINUX:
				return getSizeOfPhysicalMemoryForLinux();
				
			case WINDOWS:
				return getSizeOfPhysicalMemoryForWindows();
				
			case MAC_OS:
				return getSizeOfPhysicalMemoryForMac();
				
			case FREE_BSD:
				return getSizeOfPhysicalMemoryForFreeBSD();
				
			case UNKNOWN:
				LOG.error("Cannot determine size of physical memory for unknown operating system");
				return -1;
				
			default:
				LOG.error("Unrecognized OS");
				return -1;
		}
	}
132622
public int getSize() {
		if (size < 0) {
			size = logCache==null ? 0 : logCache.getSize();
			size += traceCache==null ? 0 : traceCache.getSize();
		}
		return size;
	}
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];
	}
1350089
def memory_usage():
    
    try:
        import psutil
        import os
    except ImportError:
        return _memory_usage_ps()

    process = psutil.Process(os.getpid())
    mem = process.memory_info()[0] / float(2 ** 20)
    return mem
341167
def get_memory(self,
	               shutit_pexpect_child=None,
	               note=None):
		""""""
		shutit_global.shutit_global_object.yield_to_draw()
		shutit_pexpect_child = shutit_pexpect_child or self.get_current_shutit_pexpect_session().pexpect_child
		shutit_pexpect_session = self.get_shutit_pexpect_session_from_child(shutit_pexpect_child)
		return shutit_pexpect_session.get_memory(note=note)