本文整理汇总了Python中mozsystemmonitor.resourcemonitor.SystemResourceMonitor.phase_usage方法的典型用法代码示例。如果您正苦于以下问题:Python SystemResourceMonitor.phase_usage方法的具体用法?Python SystemResourceMonitor.phase_usage怎么用?Python SystemResourceMonitor.phase_usage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mozsystemmonitor.resourcemonitor.SystemResourceMonitor
的用法示例。
在下文中一共展示了SystemResourceMonitor.phase_usage方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_phases
# 需要导入模块: from mozsystemmonitor.resourcemonitor import SystemResourceMonitor [as 别名]
# 或者: from mozsystemmonitor.resourcemonitor.SystemResourceMonitor import phase_usage [as 别名]
def test_phases(self):
monitor = SystemResourceMonitor(poll_interval=0.25)
monitor.start()
time.sleep(1)
with monitor.phase('phase1'):
time.sleep(1)
with monitor.phase('phase2'):
time.sleep(1)
monitor.stop()
self.assertEqual(len(monitor.phases), 2)
self.assertEqual(['phase2', 'phase1'], monitor.phases.keys())
all = list(monitor.range_usage())
data1 = list(monitor.phase_usage('phase1'))
data2 = list(monitor.phase_usage('phase2'))
self.assertGreater(len(all), len(data1))
self.assertGreater(len(data1), len(data2))
# This could fail if time.time() takes more than 0.1s. It really
# shouldn't.
self.assertAlmostEqual(data1[-1].end, data2[-1].end, delta=0.25)