Python resource.getpagesize() Examples

The following are 13 code examples of resource.getpagesize(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module resource , or try the search function .
Example #1
Source File: free_pages.py    From libvirt-test-API with GNU General Public License v2.0 7 votes vote down vote up
def check_free_pages(page_list, cell_id, free_page, logger):
    """ check page size
    """
    for ps in page_list:
        # if pagesize is equal to system pagesize, since it is hard to
        # calculate, so we just pass it
        if resource.getpagesize() / 1024 == ps:
            logger.info("skip to check default %sKB-page" % ps)
            continue

        sysfs_path = HUGEPAGE_PATH % (cell_id, ps)
        if not os.access(sysfs_path, os.R_OK):
            logger.error("could not find %s" % sysfs_path)
            return False
        f = open(sysfs_path)
        fp = int(f.read())
        f.close()
        if not fp == free_page[0][ps]:
            logger.error("Free %sKB page checking failed" % ps)
            return False
        logger.info("Free %sKB page: %s" % (ps, fp))

    return True 
Example #2
Source File: msg.py    From libnl with GNU Lesser General Public License v2.1 6 votes vote down vote up
def nlmsg_alloc(len_=default_msg_size):
    """Allocate a new Netlink message with maximum payload size specified.

    https://github.com/thom311/libnl/blob/libnl3_2_25/lib/msg.c#L299

    Allocates a new Netlink message without any further payload. The maximum payload size defaults to
    resource.getpagesize() or as otherwise specified with nlmsg_set_default_size().

    Returns:
    Newly allocated Netlink message (nl_msg class instance).
    """
    len_ = max(libnl.linux_private.netlink.nlmsghdr.SIZEOF, len_)
    nm = nl_msg()
    nm.nm_refcnt = 1
    nm.nm_nlh = libnl.linux_private.netlink.nlmsghdr(bytearray(b'\0') * len_)
    nm.nm_protocol = -1
    nm.nm_size = len_
    nm.nm_nlh.nlmsg_len = nlmsg_total_size(0)
    _LOGGER.debug('msg 0x%x: Allocated new message, maxlen=%d', id(nm), len_)
    return nm 
Example #3
Source File: netstat.py    From python-scripts with GNU General Public License v3.0 6 votes vote down vote up
def main():
    """Main loop"""
    sys.stdin.close()

    interval = 15
    page_size = resource.getpagesize()

    try:
        sockstat = open("/proc/net/sockstat")
        netstat = open("/proc/net/netstat")
        snmp = open("/proc/net/snmp")
    except IOError, e:
        print >>sys.stderr, "open failed: %s" % e
        return 13  # Ask tcollector to not re-start us.
    #utils.drop_privileges()

    # Note: up until v2.6.37-rc2 most of the values were 32 bits.
    # The first value is pretty useless since it accounts for some
    # socket types but not others.  So we don't report it because it's
    # more confusing than anything else and it's not well documented
    # what type of sockets are or aren't included in this count. 
Example #4
Source File: test_system.py    From vnpy_crypto with MIT License 5 votes vote down vote up
def test_PAGESIZE(self):
        # pagesize is used internally to perform different calculations
        # and it's determined by using SC_PAGE_SIZE; make sure
        # getpagesize() returns the same value.
        import resource
        self.assertEqual(os.sysconf("SC_PAGE_SIZE"), resource.getpagesize()) 
Example #5
Source File: test_system.py    From psutil with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_PAGESIZE(self):
        # pagesize is used internally to perform different calculations
        # and it's determined by using SC_PAGE_SIZE; make sure
        # getpagesize() returns the same value.
        import resource
        self.assertEqual(os.sysconf("SC_PAGE_SIZE"), resource.getpagesize()) 
Example #6
Source File: MemoryUsageLoop.py    From ufora with Apache License 2.0 5 votes vote down vote up
def memoryWriteLoop(logfileLocation, interval):
    try:
        if isinstance(logfileLocation, file):
            outputFile = logfileLocation
        else:
            outputFile = open(logfileLocation, "w", 0)

        def pad(s, finalLength):
            return s + " " * (finalLength - len(s))

        def formatCols(columns):
            return "".join([pad(columns[0],30)] + [pad(c, 15) for c in columns[1:]])

        columns = ["timestamp", "total size MB", "RSS MB", "shared MB", "code MB", "stack MB", "library MB", "dirty MB"]

        print >> outputFile, formatCols(columns)
        while True:
            with open("/proc/%s/statm" % os.getpid(), "r") as f:
                data = ["%.2f" % (int(x) * resource.getpagesize() / 1024 / 1024.0) for x in f.readline().split(" ")]

            print >> outputFile, formatCols([time.strftime("%Y-%m-%dT%H:%M:%S")] + data)

            time.sleep(interval)
    except:
        import traceback
        traceback.format_exc() 
Example #7
Source File: check_imaging_leaks.py    From python3_ios with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _get_mem_usage(self):
        from resource import getpagesize, getrusage, RUSAGE_SELF
        mem = getrusage(RUSAGE_SELF).ru_maxrss
        return mem * getpagesize() / 1024 / 1024 
Example #8
Source File: train.py    From incremental-sequence-learning with MIT License 5 votes vote down vote up
def memusage( point = "") :
    usage = resource.getrusage( resource.RUSAGE_SELF) 
    return '''%s: usertime = %s systime = %s mem = %s mb
           '''%( point, usage[ 0 ], usage[ 1 ], 
                ( usage[ 2 ]*resource.getpagesize( ) ) /1000000.0 ) 
Example #9
Source File: a_dataset_type.py    From accelerator with Apache License 2.0 5 votes vote down vote up
def map_init(vars, name, z='badmap_size'):
	if not vars.badmap_size:
		pagesize = getpagesize()
		line_count = vars.lines[vars.sliceno]
		vars.badmap_size = (line_count // 8 // pagesize + 1) * pagesize
		vars.slicemap_size = (line_count * 2 // pagesize + 1) * pagesize
	fh = open(name, 'w+b')
	vars.map_fhs.append(fh)
	fh.truncate(vars[z])
	return fh.fileno() 
Example #10
Source File: serval.py    From serval with MIT License 5 votes vote down vote up
def Using(point, verb=False):
    usage = resource.getrusage(resource.RUSAGE_SELF)
    if verb: print '%s: usertime=%s systime=%s mem=%s mb' % (point,usage[0],usage[1],
                (usage[2]*resource.getpagesize())/1000000.0 )
    return (usage[2]*resource.getpagesize())/1000000.0 
Example #11
Source File: cpu_linux.py    From apm-agent-python with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def __init__(self, registry, sys_stats_file=SYS_STATS, process_stats_file=PROC_STATS, memory_stats_file=MEM_STATS):
        self.page_size = resource.getpagesize()
        self.previous = {}
        self._read_data_lock = threading.Lock()
        self.sys_stats_file = sys_stats_file
        self.process_stats_file = process_stats_file
        self.memory_stats_file = memory_stats_file
        self._sys_clock_ticks = os.sysconf("SC_CLK_TCK")
        with self._read_data_lock:
            self.previous.update(self.read_process_stats())
            self.previous.update(self.read_system_stats())
        super(CPUMetricSet, self).__init__(registry) 
Example #12
Source File: benchmarkTarfile.py    From ratarmount with MIT License 5 votes vote down vote up
def memoryUsage():
    statm_labels = [ 'size', 'resident', 'shared', 'text', 'lib', 'data', 'dirty pages' ]
    values = [ int( x ) * resource.getpagesize()
               for x in open( '/proc/{}/statm'.format( os.getpid() ), 'rt' ).read().split( ' ' ) ]
    return dict( zip( statm_labels, values ) ) 
Example #13
Source File: test_system.py    From jarvis with GNU General Public License v2.0 5 votes vote down vote up
def test_PAGESIZE(self):
        # pagesize is used internally to perform different calculations
        # and it's determined by using SC_PAGE_SIZE; make sure
        # getpagesize() returns the same value.
        import resource
        self.assertEqual(os.sysconf("SC_PAGE_SIZE"), resource.getpagesize())