本文整理汇总了Python中psutil.version_info方法的典型用法代码示例。如果您正苦于以下问题:Python psutil.version_info方法的具体用法?Python psutil.version_info怎么用?Python psutil.version_info使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类psutil
的用法示例。
在下文中一共展示了psutil.version_info方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_num_cores
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import version_info [as 别名]
def get_num_cores():
import psutil
version = psutil.version_info
# Installation of OpenStack Kilo uses pstuil version 1.2.1
p = psutil.Process()
if version >= (2, 0):
return len(p.cpu_affinity())
else:
try:
# psutil 1.2.1 has issue with large number of cores
# https://github.com/giampaolo/psutil/issues/522
cores = len(p.get_cpu_affinity())
except OSError as e:
import affinity
cores = len(affinity.sched_getaffinity(p.pid))
return cores
示例2: test_version
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import version_info [as 别名]
def test_version(self):
self.assertEqual('.'.join([str(x) for x in psutil.version_info]),
psutil.__version__)
示例3: LogHostMemoryUsage
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import version_info [as 别名]
def LogHostMemoryUsage(top_n=10, level=logging.INFO):
if not psutil:
logging.warning('psutil module is not found, skipping logging memory info')
return
if psutil.version_info < (2, 0):
logging.warning('psutil %s too old, upgrade to version 2.0 or higher'
' for memory usage information.', psutil.__version__)
return
# TODO(crbug.com/777865): Remove the following pylint disable. Even if we
# check for a recent enough psutil version above, the catapult presubmit
# builder (still running some old psutil) fails pylint checks due to API
# changes in psutil.
# pylint: disable=no-member
mem = psutil.virtual_memory()
logging.log(level, 'Used %s out of %s memory available.',
FormatBytes(mem.used), FormatBytes(mem.total))
logging.log(level, 'Memory usage of top %i processes groups', top_n)
pinfos_by_names = {}
for p in psutil.process_iter():
try:
pinfo = _GetProcessInfo(p)
except psutil.NoSuchProcess:
logging.exception('process %s no longer exists', p)
continue
pname = pinfo['name']
if pname not in pinfos_by_names:
pinfos_by_names[pname] = {'name': pname, 'total_mem_rss': 0, 'pids': []}
pinfos_by_names[pname]['total_mem_rss'] += pinfo['mem_rss']
pinfos_by_names[pname]['pids'].append(str(pinfo['pid']))
sorted_pinfo_groups = heapq.nlargest(
top_n, pinfos_by_names.values(), key=lambda item: item['total_mem_rss'])
for group in sorted_pinfo_groups:
group['total_mem_rss_fmt'] = FormatBytes(group['total_mem_rss'])
group['pids_fmt'] = ', '.join(group['pids'])
logging.log(
level, '- %(name)s - %(total_mem_rss_fmt)s - pids: %(pids)s', group)
logging.log(level, 'Current process:')
pinfo = _GetProcessInfo(psutil.Process(os.getpid()))
_LogProcessInfo(pinfo, level)
示例4: set_num_cores
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import version_info [as 别名]
def set_num_cores(num_cores):
import psutil
version = psutil.version_info
# Installation of OpenStack Kilo uses pstuil version 1.2.1
if version >= (2, 0):
cpu_count = psutil.cpu_count()
num_cores = min(cpu_count, num_cores)
p = psutil.Process()
desired_cpus = list(range(num_cores))
p.cpu_affinity(desired_cpus)
updated_cpu = p.cpu_affinity()
else:
# version below 2.0
cpu_count = psutil.NUM_CPUS
num_cores = min(cpu_count, num_cores)
p = psutil.Process()
desired_cpus = list(range(num_cores))
p.set_cpu_affinity(desired_cpus)
try:
# psutil 1.2.1 has issue with large number of cores
# https://github.com/giampaolo/psutil/issues/522
updated_cpu = p.get_cpu_affinity()
except OSError as e:
updated_cpu = desired_cpus
pass
if desired_cpus != updated_cpu:
raise Exception(
"Cannot not set affinity mask: from %s to %s" %
(desired_cpus, updated_cpu))