本文整理汇总了Python中resource.getpagesize方法的典型用法代码示例。如果您正苦于以下问题:Python resource.getpagesize方法的具体用法?Python resource.getpagesize怎么用?Python resource.getpagesize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类resource
的用法示例。
在下文中一共展示了resource.getpagesize方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: check_free_pages
# 需要导入模块: import resource [as 别名]
# 或者: from resource import getpagesize [as 别名]
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
示例2: nlmsg_alloc
# 需要导入模块: import resource [as 别名]
# 或者: from resource import getpagesize [as 别名]
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
示例3: main
# 需要导入模块: import resource [as 别名]
# 或者: from resource import getpagesize [as 别名]
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.
示例4: test_PAGESIZE
# 需要导入模块: import resource [as 别名]
# 或者: from resource import getpagesize [as 别名]
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())
示例5: memoryWriteLoop
# 需要导入模块: import resource [as 别名]
# 或者: from resource import getpagesize [as 别名]
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()
示例6: _get_mem_usage
# 需要导入模块: import resource [as 别名]
# 或者: from resource import getpagesize [as 别名]
def _get_mem_usage(self):
from resource import getpagesize, getrusage, RUSAGE_SELF
mem = getrusage(RUSAGE_SELF).ru_maxrss
return mem * getpagesize() / 1024 / 1024
示例7: memusage
# 需要导入模块: import resource [as 别名]
# 或者: from resource import getpagesize [as 别名]
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 )
示例8: map_init
# 需要导入模块: import resource [as 别名]
# 或者: from resource import getpagesize [as 别名]
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()
示例9: Using
# 需要导入模块: import resource [as 别名]
# 或者: from resource import getpagesize [as 别名]
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
示例10: __init__
# 需要导入模块: import resource [as 别名]
# 或者: from resource import getpagesize [as 别名]
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)
示例11: memoryUsage
# 需要导入模块: import resource [as 别名]
# 或者: from resource import getpagesize [as 别名]
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 ) )