本文整理匯總了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))