Set the memory per process in megabytes
518023
def set_mem_per_proc(self, mem_mb):
        """"""
        super().set_mem_per_proc(mem_mb)
        self.qparams["mem_per_cpu"] = self.mem_per_proc
236101
public void putMemorySize(String key, MemorySize size) {
		checkNotNull(key);
		checkNotNull(size);
		put(key, size.toString());
	}
345615
def write_memory(self, addr, value, transfer_size=32):
        
        self.ap.write_memory(addr, value, transfer_size)
885072
def copy(self):
        
        s = MemoryData(self.address, self.size, self.sort, pointer_addr=self.pointer_addr, max_size=self.max_size)
        s.content = self.content

        return s
1242324
private function _memory()
    {
        if (CommonFunctions::rfts('/proc/meminfo', $bufr)) {
            $bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
            foreach ($bufe as $buf) {
                if (preg_match('/Mem:\s+(.*)$/', $buf, $ar_buf)) {
                    $ar_buf = preg_split('/\s+/', $ar_buf[1], 6);
                    $this->sys->setMemTotal($ar_buf[0]);
                    $this->sys->setMemUsed($ar_buf[1]);
                    $this->sys->setMemFree($ar_buf[2]);
                    $this->sys->setMemApplication($ar_buf[3]);
                    $this->sys->setMemBuffer($ar_buf[4]);
                    $this->sys->setMemCache($ar_buf[5]);
                }
                // Get info on individual swap files
                if (CommonFunctions::rfts('/proc/swaps', $swaps)) {
                    $swapdevs = preg_split("/\n/", $swaps, -1, PREG_SPLIT_NO_EMPTY);
                    for ($i = 1, $max = (sizeof($swapdevs) - 1); $i < $max; $i++) {
                        $ar_buf = preg_split('/\s+/', $swapdevs[$i], 6);
                        $dev = new DiskDevice();
                        $dev->setMountPoint($ar_buf[0]);
                        $dev->setName("SWAP");
                        $dev->setFsType('swap');
                        $dev->setTotal($ar_buf[2] * 1024);
                        $dev->setUsed($ar_buf[3] * 1024);
                        $dev->setFree($dev->getTotal() - $dev->getUsed());
                        $this->sys->setSwapDevices($dev);
                    }
                }
            }
        }
    }
1060714
def disk2ram(self):
        """"""
        values = self.series
        self.deactivate_disk()
        self.ramflag = True
        self.__set_array(values)
        self.update_fastaccess()
951619
private function _memory()
    {
        if ($this->_wmi) {
            $buffer = $this->_get_Win32_OperatingSystem();
            if ($buffer) {
                $this->sys->setMemTotal($buffer[0]['TotalVisibleMemorySize'] * 1024);
                $this->sys->setMemFree($buffer[0]['FreePhysicalMemory'] * 1024);
                $this->sys->setMemUsed($this->sys->getMemTotal() - $this->sys->getMemFree());
            }
            $buffer = CommonFunctions::getWMI($this->_wmi, 'Win32_PageFileUsage');
            foreach ($buffer as $swapdevice) {
                $dev = new DiskDevice();
                $dev->setName("SWAP");
                $dev->setMountPoint($swapdevice['Name']);
                $dev->setTotal($swapdevice['AllocatedBaseSize'] * 1024 * 1024);
                $dev->setUsed($swapdevice['CurrentUsage'] * 1024 * 1024);
                $dev->setFree($dev->getTotal() - $dev->getUsed());
                $dev->setFsType('swap');
                $this->sys->setSwapDevices($dev);
            }
        } elseif (($buffer = $this->_get_systeminfo()) && preg_match("/:\s([\d \xFF]+)\sMB\r\n.+:\s([\d \xFF]+)\sMB\r\n.+:\s([\d \xFF]+)\sMB\r\n.+:\s([\d \xFF]+)\sMB\r\n.+\s([\d \xFF]+)\sMB\r\n/m", $buffer, $buffer2)) {
//           && (preg_match("/:\s([\d \xFF]+)\sMB\r\n.+:\s([\d \xFF]+)\sMB\r\n.+:\s([\d \xFF]+)\sMB\r\n.+:\s([\d \xFF]+)\sMB\r\n.+\s([\d \xFF]+)\sMB\r\n.*:\s+(\S+)\r\n/m", $buffer, $buffer2)) {
            $this->sys->setMemTotal(preg_replace('/(\s)|(\xFF)/', '', $buffer2[1]) * 1024 * 1024);
            $this->sys->setMemFree(preg_replace('/(\s)|(\xFF)/', '', $buffer2[2]) * 1024 * 1024);
            $this->sys->setMemUsed($this->sys->getMemTotal() - $this->sys->getMemFree());
        }
    }
1288135
def current_memory_usage():
    
    import psutil
    proc = psutil.Process(os.getpid())
    #meminfo = proc.get_memory_info()
    meminfo = proc.memory_info()
    rss = meminfo[0]  # Resident Set Size / Mem Usage
    vms = meminfo[1]  # Virtual Memory Size / VM Size  # NOQA
    return rss
1319675
def __set_byte(self, byte, lineno):
        
        if byte < 0 or byte > 255:
            error(lineno, 'Invalid byte value %i' % byte)

        self.memory_bytes[self.org] = byte
        self.index += 1
782615
private function _memory()
    {
        $mems = "";
        $tswap = "";
        $pswap = "";
        foreach ($this->readaixdata() as $line) {
            if (preg_match("/^Good Memory Size:\s+(\d+)\s+MB/", $line, $ar_buf)) {
                $mems = $ar_buf[1];
            }
            if (preg_match("/^\s*Total Paging Space:\s+(\d+)MB/", $line, $ar_buf)) {
                $tswap = $ar_buf[1];
            }
            if (preg_match("/^\s*Percent Used:\s+(\d+)%/", $line, $ar_buf)) {
                $pswap = $ar_buf[1];
            }
        }
        if (trim($mems) != "") {
            $mems = $mems*1024*1024;
            $this->sys->setMemTotal($mems);
            $memu = 0;
            $memf = 0;
            if (CommonFunctions::executeProgram('svmon', '-G', $buf)) {
                if (preg_match("/^memory\s+\d+\s+(\d+)\s+/", $buf, $ar_buf)) {
                    $memu = $ar_buf[1]*1024*4;
                    $memf = $mems - $memu;
                }
            }
            $this->sys->setMemUsed($memu);
            $this->sys->setMemFree($memf);
//            $this->sys->setMemApplication($mems);
//            $this->sys->setMemBuffer($mems);
//            $this->sys->setMemCache($mems);
        }
        if (trim($tswap) != "") {
            $dev = new DiskDevice();
            $dev->setName("SWAP");
            $dev->setFsType('swap');
            $dev->setTotal($tswap * 1024 * 1024);
            if (trim($pswap) != "") {
                $dev->setUsed($dev->getTotal() * $pswap / 100);
            }
            $dev->setFree($dev->getTotal() - $dev->getUsed());
            $this->sys->setSwapDevices($dev);
        }
    }
756065
def run_in_memory(args, edges):
    """"""
    # Create an OSLOM runner with a temporary working directory
    oslom_runner = OslomRunner(tempfile.mkdtemp())

    # Write temporary edges file with re-mapped Ids
    logging.info("writing temporary edges file with re-mapped Ids ...")
    oslom_runner.store_edges(edges)

    # Run OSLOM
    logging.info("running OSLOM ...")
    log_file = os.path.join(oslom_runner.working_dir, OSLOM_LOG_FILE)
    result = oslom_runner.run(args.oslom_exec, args.oslom_args, log_file)
    with open(log_file, "r") as reader:
        oslom_log = reader.read()
    if result["retval"] != 0:
        logging.error("error running OSLOM, check the log")
        return (None, oslom_log)
    logging.info("OSLOM executed in %.3f secs", result["time"])

    # Read back clusters found by OSLOM
    logging.info("reading OSLOM clusters output file ...")
    clusters = oslom_runner.read_clusters(args.min_cluster_size)
    logging.info(
        "found %d cluster(s) and %d with size >= %d",
        clusters["num_found"], len(clusters["clusters"]), args.min_cluster_size)

    # Clean-up temporary working directory
    oslom_runner.cleanup()

    # Finished
    logging.info("finished")
    return (clusters, oslom_log)
1313075
def _memory_usage(self, pid='self', category="hwm", container=None):
        
        if container:
            # TODO: Put some debug output here with switch to Logger
            # since this is relatively untested.
            cmd = "docker stats " + container + " --format '{{.MemUsage}}' --no-stream"
            mem_use_str = subprocess.check_output(cmd, shell=True)
            mem_use = mem_use_str.split("/")[0].split()
            
            mem_num = re.findall('[\d\.]+', mem_use_str.split("/")[0])[0]
            mem_scale = re.findall('[A-Za-z]+', mem_use_str.split("/")[0])[0]

            #print(mem_use_str, mem_num, mem_scale)
            mem_num = float(mem_num)
            if mem_scale == "GiB":
                return mem_num * 1e6
            elif mem_scale == "MiB":
                return mem_num * 1e3
            elif mem_scale == "KiB":
                return mem_num
            else:
                # What type is this?
                return 0

        # Thanks Martin Geisler:
        status = None
        result = {'peak': 0, 'rss': 0, 'hwm': 0}
        
        try:
            # This will only work on systems with a /proc file system
            # (like Linux).
            # status = open('/proc/self/status')
            proc_spot = '/proc/%s/status' % pid
            status = open(proc_spot)
            for line in status:
                parts = line.split()
                key = parts[0][2:-1].lower()
                if key in result:
                    result[key] = int(parts[1])
        except:
            return 0

        finally:
            if status is not None:
                status.close()
        # print(result[category])
        return result[category]
96173
def get_memory(self, start, size):
        
        LOG.debug('get_memory: %d bytes from %x', size, start)
        return get_memory(self.ida.idaapi, start, size,
                          default_byte=self.default_byte)
261125
def setmem(vm_, memory):
    '''
    
    '''
    with _get_xapi_session() as xapi:
        mem_target = int(memory) * 1024 * 1024

        vm_uuid = _get_label_uuid(xapi, 'VM', vm_)
        if vm_uuid is False:
            return False
        try:
            xapi.VM.set_memory_dynamic_max_live(vm_uuid, mem_target)
            xapi.VM.set_memory_dynamic_min_live(vm_uuid, mem_target)
            return True
        except Exception:
            return False
586244
def log_memory(log, pref=None, lvl=logging.DEBUG, raise_flag=True):
    
    import os
    import sys
    cyc_str = ""
    KB = 1024.0
    if pref is not None:
        cyc_str += "{}: ".format(pref)

    # Linux returns units in Bytes; OSX in kilobytes
    UNIT = KB*KB if sys.platform == 'darwin' else KB

    good = False
    # Use the `resource` module to check the maximum memory usage of this process
    try:
        import resource
        max_self = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss
        max_child = resource.getrusage(resource.RUSAGE_CHILDREN).ru_maxrss
        _str = "RSS Max Self: {:7.2f} [MB], Child: {:7.2f} [MB]".format(
            max_self/UNIT, max_child/UNIT)
        cyc_str += _str
    except Exception as err:
        log.log(lvl, "resource.getrusage failed.  '{}'".format(str(err)))
        if raise_flag:
            raise
    else:
        good = True

    # Use the `psutil` module to check the current memory/cpu usage of this process
    try:
        import psutil
        process = psutil.Process(os.getpid())
        rss = process.memory_info().rss
        cpu_perc = process.cpu_percent()
        mem_perc = process.memory_percent()
        num_thr = process.num_threads()
        _str = "; RSS: {:7.2f} [MB], {:7.2f}%; Threads: {:3d}, CPU: {:7.2f}%".format(
            rss/UNIT, mem_perc, num_thr, cpu_perc)
        cyc_str += _str
    except Exception as err:
        log.log(lvl, "psutil.Process failed.  '{}'".format(str(err)))
        if raise_flag:
            raise
    else:
        good = True

    if good:
        log.log(lvl, cyc_str)

    return
291844
function ProcessMemoryDump(globalMemoryDump, process, start) {
    tr.model.ContainerMemoryDump.call(this, start);
    this.process = process;
    this.globalMemoryDump = globalMemoryDump;

    // Process memory totals (optional object) with the following fields (also
    // optional):
    //   - residentBytes: Total resident bytes (number)
    //   - peakResidentBytes: Peak resident bytes (number)
    //   - arePeakResidentBytesResettable: Flag whether peak resident bytes are
    //     resettable (boolean)
    //   - platformSpecific: Map from OS-specific total names (string) to sizes
    //     (number)
    this.totals = undefined;

    this.vmRegions_ = undefined;

    // Map from allocator names to heap dumps.
    this.heapDumps = undefined;

    this.tracingOverheadOwnershipSetUp_ = false;
    this.tracingOverheadDiscountedFromVmRegions_ = false;
  }
1147509
private function _memory()
    {
        if (CommonFunctions::rfts('/proc/meminfo', $bufr, 1, 4096, false)) {
            $ar_buf = preg_split('/\s+/', trim($bufr));
            if (count($ar_buf) >= 5) {
                    $this->sys->setMemTotal($ar_buf[0]*$ar_buf[1]);
                    $this->sys->setMemFree($ar_buf[0]*$ar_buf[2]);
                    $this->sys->setMemCache($ar_buf[0]*$ar_buf[4]);
                    $this->sys->setMemUsed($ar_buf[0]*($ar_buf[1]-$ar_buf[2]));
            }
        }
    }