本文整理汇总了Python中mozsystemmonitor.resourcemonitor.SystemResourceMonitor.aggregate_cpu_percent方法的典型用法代码示例。如果您正苦于以下问题:Python SystemResourceMonitor.aggregate_cpu_percent方法的具体用法?Python SystemResourceMonitor.aggregate_cpu_percent怎么用?Python SystemResourceMonitor.aggregate_cpu_percent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mozsystemmonitor.resourcemonitor.SystemResourceMonitor
的用法示例。
在下文中一共展示了SystemResourceMonitor.aggregate_cpu_percent方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_aggregate_cpu
# 需要导入模块: from mozsystemmonitor.resourcemonitor import SystemResourceMonitor [as 别名]
# 或者: from mozsystemmonitor.resourcemonitor.SystemResourceMonitor import aggregate_cpu_percent [as 别名]
def test_aggregate_cpu(self):
monitor = SystemResourceMonitor(poll_interval=0.25)
monitor.start()
time.sleep(1)
monitor.stop()
values = monitor.aggregate_cpu_percent()
self.assertIsInstance(values, list)
self.assertEqual(len(values), multiprocessing.cpu_count())
for v in values:
self.assertIsInstance(v, float)
value = monitor.aggregate_cpu_percent(per_cpu=False)
self.assertIsInstance(value, float)
values = monitor.aggregate_cpu_times()
self.assertIsInstance(values, list)
self.assertGreater(len(values), 0)
self.assertTrue(hasattr(values[0], 'user'))
t = type(values[0])
value = monitor.aggregate_cpu_times(per_cpu=False)
self.assertIsInstance(value, t)
示例2: BuildMonitor
# 需要导入模块: from mozsystemmonitor.resourcemonitor import SystemResourceMonitor [as 别名]
# 或者: from mozsystemmonitor.resourcemonitor.SystemResourceMonitor import aggregate_cpu_percent [as 别名]
#.........这里部分代码省略.........
return None, None, None
swap_in = sum(m.swap.sin for m in self.resources.measurements)
swap_out = sum(m.swap.sout for m in self.resources.measurements)
# The threshold of 1024 MB has been arbitrarily chosen.
#
# Choosing a proper value that is ideal for everyone is hard. We will
# likely iterate on the logic until people are generally satisfied.
# If a value is too low, the eventual warning produced does not carry
# much meaning. If the threshold is too high, people may not see the
# warning and the warning will thus be ineffective.
excessive = swap_in > 512 * 1048576 or swap_out > 512 * 1048576
return excessive, swap_in, swap_out
@property
def have_resource_usage(self):
"""Whether resource usage is available."""
return self.resources.start_time is not None
def record_resource_usage(self):
"""Record the resource usage of this build.
We write a log message containing a high-level summary. We also produce
a data structure containing the low-level resource usage information.
This data structure can e.g. be serialized into JSON and saved for
subsequent analysis.
If no resource usage is available, None is returned.
"""
if not self.have_resource_usage:
return None
cpu_percent = self.resources.aggregate_cpu_percent(phase=None,
per_cpu=False)
cpu_times = self.resources.aggregate_cpu_times(phase=None,
per_cpu=False)
io = self.resources.aggregate_io(phase=None)
self._log_resource_usage('Overall system resources', 'resource_usage',
self.end_time - self.start_time, cpu_percent, cpu_times, io)
excessive, sin, sout = self.have_excessive_swapping()
if excessive is not None and (sin or sout):
sin /= 1048576
sout /= 1048576
self.log(logging.WARNING, 'swap_activity',
{'sin': sin, 'sout': sout},
'Swap in/out (MB): {sin}/{sout}')
o = dict(
version=1,
start=self.start_time,
end=self.end_time,
duration=self.end_time - self.start_time,
resources=[],
cpu_percent=cpu_percent,
cpu_times=cpu_times,
io=io,
)
o['tiers'] = self.tiers.tiered_resource_usage()
self.tiers.add_resource_fields_to_dict(o)
for usage in self.resources.range_usage():
示例3: BuildMonitor
# 需要导入模块: from mozsystemmonitor.resourcemonitor import SystemResourceMonitor [as 别名]
# 或者: from mozsystemmonitor.resourcemonitor.SystemResourceMonitor import aggregate_cpu_percent [as 别名]
#.........这里部分代码省略.........
"""
if not self.have_resource_usage:
return None, None, None
swap_in = sum(m.swap.sin for m in self.resources.measurements)
swap_out = sum(m.swap.sout for m in self.resources.measurements)
# The threshold of 1024 MB has been arbitrarily chosen.
#
# Choosing a proper value that is ideal for everyone is hard. We will
# likely iterate on the logic until people are generally satisfied.
# If a value is too low, the eventual warning produced does not carry
# much meaning. If the threshold is too high, people may not see the
# warning and the warning will thus be ineffective.
excessive = swap_in > 512 * 1048576 or swap_out > 512 * 1048576
return excessive, swap_in, swap_out
@property
def have_resource_usage(self):
"""Whether resource usage is available."""
return self.resources.start_time is not None
def get_resource_usage(self):
""" Produce a data structure containing the low-level resource usage information.
This data structure can e.g. be serialized into JSON and saved for
subsequent analysis.
If no resource usage is available, None is returned.
"""
if not self.have_resource_usage:
return None
cpu_percent = self.resources.aggregate_cpu_percent(phase=None, per_cpu=False)
cpu_times = self.resources.aggregate_cpu_times(phase=None, per_cpu=False)
io = self.resources.aggregate_io(phase=None)
o = dict(
version=3,
argv=sys.argv,
start=self.start_time,
end=self.end_time,
duration=self.end_time - self.start_time,
resources=[],
cpu_percent=cpu_percent,
cpu_times=cpu_times,
io=io,
objects=self.build_objects,
)
o["tiers"] = self.tiers.tiered_resource_usage()
self.tiers.add_resource_fields_to_dict(o)
for usage in self.resources.range_usage():
cpu_percent = self.resources.aggregate_cpu_percent(usage.start, usage.end, per_cpu=False)
cpu_times = self.resources.aggregate_cpu_times(usage.start, usage.end, per_cpu=False)
entry = dict(start=usage.start, end=usage.end, virt=list(usage.virt), swap=list(usage.swap))
self.tiers.add_resources_to_dict(entry, start=usage.start, end=usage.end)
o["resources"].append(entry)
# If the imports for this file ran before the in-tree virtualenv
# was bootstrapped (for instance, for a clobber build in automation),