Пример #1
0
    def test_telemetry_in_place_leaf_cgroup(self):
        """
        Ensure this leaf (i.e. not root of cgroup tree) cgroup has distinct metrics from the root cgroup.
        """
        # Does nothing on systems where the default cgroup for a randomly-created process (like this test invocation)
        # is the root cgroup.
        cg = make_self_cgroups()
        root = make_root_cgroups()
        if cg.cgroups['cpu'] != root.cgroups['cpu']:
            ct = CGroupsTelemetry("test", cg)
            cpu = CpuCgroup(ct)
            self.assertLess(cpu._current_cpu_total, cpu._current_system_cpu)

            consume_cpu_time()  # Eat some CPU
            time.sleep(1)  # Generate some idle time
            cpu._update_cpu_data()
            self.assertLess(cpu._current_cpu_total, cpu._current_system_cpu)
Пример #2
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)
Пример #3
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)