Esempio n. 1
0
    def test_update_cpu_metrics(self):
        """Tests updating cpu stats from cgroups."""
        cpumetrics = metrics.read_cpu_stats('treadmill/apps/appname')

        cpu_usage = 100
        cpu_ratio = .5
        time_delta = 10
        cpu_count = 1
        cpu_shares = 10
        total_bogomips = 100

        requested_ratio = cpu_ratio * 100
        usage_ratio = ((cpu_usage * total_bogomips) /
                       (time_delta * cpu_shares) / cpu_count)
        usage = ((cpu_usage * total_bogomips) /
                 (time_delta * sysinfo.BMIPS_PER_CPU) / cpu_count * 100)

        self.assertEquals((usage, requested_ratio, usage_ratio), cpumetrics)
Esempio n. 2
0
    def test_read_cpu_metrics(self):
        """Tests updating cpu stats from cgroups."""
        cpumetrics = metrics.read_cpu_stats('treadmill/apps/appname')

        self.assertEqual(
            cpumetrics, {
                'cpu.stat': {
                    'nr_periods': 0,
                    'nr_throttled': 0,
                    'throttled_time': 0
                },
                'cpuacct.stat': {
                    'system': 309900720000000,
                    'user': 183352600000000
                },
                'cpuacct.usage': 100,
                'cpu.shares': 1024,
                'cpuacct.usage_percpu': [50, 50]
            })