Exemplo n.º 1
0
    def test_telemetry_inplace(self):
        """
        Test raw measures and basic statistics for the cgroup in which this process is currently running.
        """
        cg = make_self_cgroups()
        self.assertIn('cpu', cg.cgroups)
        self.assertIn('memory', cg.cgroups)
        ct = CGroupsTelemetry("test", cg)
        cpu = CpuCgroup(ct)
        self.assertGreater(cpu._current_system_cpu, 0)

        consume_cpu_time()  # Eat some CPU
        cpu._update_cpu_data()

        self.assertGreater(cpu._current_cpu_total, cpu._previous_cpu_total)
        self.assertGreater(cpu._current_system_cpu, cpu._previous_system_cpu)

        percent_used = cpu._get_cpu_percent()
        self.assertGreater(percent_used, 0)
Exemplo n.º 2
0
 def test_cpu_telemetry(self):
     """
     Test Cpu telemetry class
     """
     cg = make_self_cgroups()
     self.assertIn('cpu', cg.cgroups)
     ct = CGroupsTelemetry('test', cg)
     self.assertIs(cg, ct.cgroup)
     cpu = CpuCgroup(ct)
     self.assertIs(cg, cpu.cgt.cgroup)
     ticks_before = cpu._current_cpu_total
     consume_cpu_time()
     time.sleep(1)
     cpu._update_cpu_data()
     ticks_after = cpu._current_cpu_total
     self.assertGreater(ticks_after, ticks_before)
     p2 = cpu._get_cpu_percent()
     self.assertGreater(p2, 0)
     # when running under PyCharm, this is often > 100
     # on a multi-core machine
     self.assertLess(p2, 200)