def test_per_cpu_times(self):
# Check type, value >= 0, str().
for times in psutil.cpu_times(percpu=True):
total = 0
sum(times)
for cp_time in times:
self.assertIsInstance(cp_time, float)
self.assertGreaterEqual(cp_time, 0.0)
total += cp_time
self.assertEqual(total, sum(times))
str(times)
self.assertEqual(len(psutil.cpu_times(percpu=True)[0]),
len(psutil.cpu_times(percpu=False)))
# Note: in theory CPU times are always supposed to increase over
# time or remain the same but never go backwards. In practice
# sometimes this is not the case.
# This issue seemd to be afflict Windows:
# https://github.com/giampaolo/psutil/issues/392
# ...but it turns out also Linux (rarely) behaves the same.
# last = psutil.cpu_times(percpu=True)
# for x in range(100):
# new = psutil.cpu_times(percpu=True)
# for index in range(len(new)):
# newcpu = new[index]
# lastcpu = last[index]
# for field in newcpu._fields:
# new_t = getattr(newcpu, field)
# last_t = getattr(lastcpu, field)
# self.assertGreaterEqual(
# new_t, last_t, msg="%s %s" % (lastcpu, newcpu))
# last = new
评论列表
文章目录