Пример #1
0
    def test_bogomips(self):
        """Mock test for mem info."""

        bogomips = sysinfo.total_bogomips()

        # bogomips  : 6385.66
        # bogomips  : 6384.64
        # bogomips  : 6385.26
        # bogomips  : 6384.10
        # -------------------
        # total     : 25539.659999999996
        self.assertEqual(25539, bogomips)
Пример #2
0
def get_cpu_metrics(cpu_usage_delta, time_delta, cpu_shares):
    """calculate cpu percentage and ratio
    """
    total_bogomips = sysinfo.total_bogomips()
    cpu_count = sysinfo.available_cpu_count()

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

    return (usage, requested_ratio, usage_ratio)
Пример #3
0
    def cginit(mem, mem_core, cpu):
        """Initialize core and system cgroups."""
        total_cpu_shares = int(sysinfo.total_bogomips())
        tm_cpu_shares = int(total_cpu_shares * utils.cpu_units(cpu) / 100.0)
        system_cpu_shares = int(total_cpu_shares - tm_cpu_shares)
        tm_core_cpu_shares = int(tm_cpu_shares * 0.01)
        tm_apps_cpu_shares = tm_cpu_shares - tm_core_cpu_shares

        _LOGGER.info('Configuring CPU limits: '
                     'total: %d, '
                     'treadmill: %d, '
                     'system: %d, '
                     'treadmill core: %d, '
                     'treadmill apps: %d',
                     total_cpu_shares,
                     tm_cpu_shares,
                     system_cpu_shares,
                     tm_core_cpu_shares,
                     tm_apps_cpu_shares)

        tm_mem = utils.size_to_bytes(mem)
        tm_core_mem = utils.size_to_bytes(mem_core)

        total_physical_mem = sysinfo.mem_info().total * 1024

        if tm_mem <= 0:
            # For readability, instead of + tm_mem (negative).
            real_tm_mem = total_physical_mem - abs(tm_mem)
        else:
            real_tm_mem = tm_mem

        _LOGGER.info('Configuring memory limits: '
                     'total: %s, '
                     'treadmill total: %s, '
                     'treadmill core: %s',
                     utils.bytes_to_readable(total_physical_mem, 'B'),
                     utils.bytes_to_readable(real_tm_mem, 'B'),
                     utils.bytes_to_readable(tm_core_mem, 'B'))

        cgutils.create_treadmill_cgroups(system_cpu_shares,
                                         tm_cpu_shares,
                                         tm_core_cpu_shares,
                                         tm_apps_cpu_shares,
                                         real_tm_mem,
                                         tm_core_mem)
Пример #4
0
def read_cpu_stats(cgrp):
    """Calculate normalized CPU stats given cgroup name.

    Returns tuple of (usage, requested, usage_ratio)
    """
    cpu_usage = cgutils.cpu_usage(cgrp)
    stat = cgutils.stat('cpuacct', cgrp, 'cpuacct.usage')
    delta = time.time() - stat.st_mtime
    cgutils.reset_cpu_usage(cgrp)

    cpu_shares = cgroups.get_cpu_shares(cgrp)
    total_bogomips = sysinfo.total_bogomips()
    cpu_count = sysinfo.available_cpu_count()

    requested_ratio = cgutils.get_cpu_ratio(cgrp) * 100
    usage_ratio = ((cpu_usage * total_bogomips) / (delta * cpu_shares) /
                   cpu_count)
    usage = ((cpu_usage * total_bogomips) / (delta * sysinfo.BMIPS_PER_CPU) /
             cpu_count * 100)

    return (usage, requested_ratio, usage_ratio)
Пример #5
0
    def test_bogomips(self):
        """Mock test for mem info."""
        cpuinfo = """
processor   : 0
vendor_id   : GenuineIntel
cpu family  : 6
model       : 58
model name  :         Intel(R) Core(TM) i5-3470 CPU @ 3.20GHz
stepping    : 9
cpu MHz     : 1600.000
cache size  : 6144 KB
physical id : 0
siblings    : 4
core id     : 0
cpu cores   : 4
apicid      : 0
fpu     : yes
fpu_exception   : yes
cpuid level : 13
wp      : yes
flags       : fpu vme de pse
bogomips    : 6385.66
clflush size    : 64
cache_alignment : 64
address sizes   : 36 bits physical, 48 bits virtual
power management: [8]

processor   : 1
vendor_id   : GenuineIntel
cpu family  : 6
model       : 58
model name  :         Intel(R) Core(TM) i5-3470 CPU @ 3.20GHz
stepping    : 9
cpu MHz     : 1600.000
cache size  : 6144 KB
physical id : 0
siblings    : 4
core id     : 1
cpu cores   : 4
apicid      : 2
fpu     : yes
fpu_exception   : yes
cpuid level : 13
wp      : yes
flags       : fpu vme de pse
bogomips    : 6384.64
clflush size    : 64
cache_alignment : 64
address sizes   : 36 bits physical, 48 bits virtual
power management: [8]

processor   : 2
vendor_id   : GenuineIntel
cpu family  : 6
model       : 58
model name  :         Intel(R) Core(TM) i5-3470 CPU @ 3.20GHz
stepping    : 9
cpu MHz     : 1600.000
cache size  : 6144 KB
physical id : 0
siblings    : 4
core id     : 2
cpu cores   : 4
apicid      : 4
fpu     : yes
fpu_exception   : yes
cpuid level : 13
wp      : yes
flags       : fpu vme de pse
bogomips    : 6385.26
clflush size    : 64
cache_alignment : 64
address sizes   : 36 bits physical, 48 bits virtual
power management: [8]

processor   : 3
vendor_id   : GenuineIntel
cpu family  : 6
model       : 58
model name  :         Intel(R) Core(TM) i5-3470 CPU @ 3.20GHz
stepping    : 9
cpu MHz     : 1600.000
cache size  : 6144 KB
physical id : 0
siblings    : 4
core id     : 3
cpu cores   : 4
apicid      : 6
fpu     : yes
fpu_exception   : yes
cpuid level : 13
wp      : yes
flags       : fpu vme de pse
bogomips    : 6384.10
clflush size    : 64
cache_alignment : 64
address sizes   : 36 bits physical, 48 bits virtual
power management: [8]

"""

        open_mock = mock.mock_open(read_data=cpuinfo.strip())
        with mock.patch('builtins.open', open_mock, create=True):
            bogomips = sysinfo.total_bogomips()

        # bogomips  : 6385.66
        # bogomips  : 6384.64
        # bogomips  : 6385.26
        # bogomips  : 6384.10
        # -------------------
        # total     : 25539.659999999996
        self.assertEqual(25539, bogomips)