def test_per_cpu_times_2(self): # Simulate some work load then make sure time have increased # between calls. tot1 = psutil.cpu_times(percpu=True) giveup_at = time.time() + 1 while True: if time.time() >= giveup_at: return self.fail("timeout") tot2 = psutil.cpu_times(percpu=True) for t1, t2 in zip(tot1, tot2): t1, t2 = psutil._cpu_busy_time(t1), psutil._cpu_busy_time(t2) difference = t2 - t1 if difference >= 0.05: return
def get_all_busy_time(): """ Get per-CPU busy times """ times = psutil.cpu_times(percpu=True) busy_times = [] for cpu in range(psutil.cpu_count()): busy_times.append(psutil._cpu_busy_time(times[cpu])) return busy_times