def test_measure_rapl_device_all_domains(_mocked_perf_counter,
                                         fs_pkg_dram_one_socket, one_gpu_api):
    domains = [RaplPackageDomain(0), RaplDramDomain(0), NvidiaGPUDomain(0)]

    correct_trace = CorrectTrace(domains,
                                 [fs_pkg_dram_one_socket, one_gpu_api],
                                 TIMESTAMP_TRACE)  # test

    rapl = RaplDevice()
    rapl.configure(domains=[RaplPackageDomain(0), RaplDramDomain(0)])

    nvidia = NvidiaGPUDevice()
    nvidia.configure(domains=[NvidiaGPUDomain(0)])

    meter = EnergyMeter([rapl, nvidia])

    correct_trace.add_new_sample('foo')  # test
    meter.start(tag="foo")

    correct_trace.add_new_sample('bar')  # test
    meter.record(tag="bar")

    correct_trace.add_new_sample('')  # test
    meter.stop()

    for sample1, sample2 in zip(correct_trace, meter):  # test
        assert_sample_are_equals(sample1, sample2)  # test
Example #2
0
def test_get_package0_and_all_dram_energy_with_pkg_dram_rapl_api_two_sockets_return_correct_value(fs_pkg_dram_two_socket):
    """
    Create a RaplDevice instance on a machine with package and dram rapl api with on two socket
    configure it to monitor package domains on socket 0 and dram domains on socket 0 and 1
    use the `get_energy` method and check if:
    - the returned list contains 3 elements
    - these elements are the power consumption of the package on socket 0 and dram on socket 0 and socket 1
    """
    device = RaplDevice()
    device.configure([RaplPackageDomain(0), RaplDramDomain(0), RaplDramDomain(1)])
    assert device.get_energy() == [fs_pkg_dram_two_socket.domains_current_energy['package_0'],
                                   fs_pkg_dram_two_socket.domains_current_energy['dram_0'],
                                   fs_pkg_dram_two_socket.domains_current_energy['dram_1']]
Example #3
0
def test_create_devices_with_rapl_package_and_dram_domains_return_one_correctly_configured_rapl_device(
        fs_pkg_dram_one_socket):
    domains = [RaplPackageDomain(0), RaplDramDomain(0)]
    devices = EnergyDeviceFactory.create_devices(domains)

    assert len(devices) == 1
    assert isinstance(devices[0], RaplDevice)
    assert devices[0].get_configured_domains() == domains
Example #4
0
def test_create_devices_with_default_values_on_machine_with_only_rapl_pkg_and_dram_api_create_one_device_configured_for_dram_and_rapl(
        fs_pkg_dram_one_socket):
    devices = EnergyDeviceFactory.create_devices()

    assert len(devices) == 1
    assert isinstance(devices[0], RaplDevice)
    assert devices[0].get_configured_domains() == [
        RaplPackageDomain(0), RaplDramDomain(0)
    ]
Example #5
0
def test_get_dram_energy_with_pkg_dram_rapl_api_return_correct_value(fs_pkg_dram_one_socket):
    """
    Create a RaplDevice instance on a machine with package and dram rapl api with on one socket
    configure it to monitor dram domain
    use the `get_energy` method and check if:
    - the returned list contains one element
    - this element is the power consumption of the dram on socket 0
    """
    device = RaplDevice()
    device.configure([RaplDramDomain(0)])
    assert device.get_energy() == [fs_pkg_dram_one_socket.domains_current_energy['dram_0']]
def test_measure_rapl_device_default_values(mocked_handler,
                                            _mocked_perf_counter,
                                            fs_pkg_dram_one_socket,
                                            one_gpu_api):

    correct_trace = CorrectTrace(
        [RaplPackageDomain(0),
         RaplDramDomain(0),
         NvidiaGPUDomain(0)], [fs_pkg_dram_one_socket, one_gpu_api],
        TIMESTAMP_TRACE)  # test

    correct_trace.add_new_sample('start')  # test
    with EnergyContext(mocked_handler) as energy_context:
        correct_trace.add_new_sample('second_tag')  # test
        energy_context.record(tag='second_tag')
        correct_trace.add_new_sample('')  # test

    assert mocked_handler.process.call_count == 2  # test

    for correct_sample, processed_arg in zip(
            correct_trace, mocked_handler.process.call_args_list):  # test
        measured_sample = processed_arg[0][0]  # test
        assert_sample_are_equals(correct_sample, measured_sample)  # test
Example #7
0
def test_create_devices_to_monitor_rapl_without_rapl_api_raise_NoSuchEnergyDeviceError(
        empty_fs):
    with pytest.raises(NoSuchEnergyDeviceError):
        EnergyDeviceFactory.create_devices([RaplDramDomain(0)])
Example #8
0
def test_create_devices_with_dram_rapl_domain_without_dram_support_raise_NoSuchDomainError(
        fs_pkg_one_socket):
    with pytest.raises(NoSuchDomainError):
        EnergyDeviceFactory.create_devices([RaplDramDomain(0)])
Example #9
0
def test_configure_device_to_get_dram_energy_with_no_rapl_dram_api_raise_NoSuchDomainError(fs_pkg_one_socket):
    device = RaplDevice()

    with pytest.raises(NoSuchDomainError):
        device.configure([RaplDramDomain(0)])
Example #10
0
def test_available_domains_with_pkg_dram_rapl_api_two_cpu_return_correct_values(fs_pkg_dram_two_socket):
    returned_values = RaplDevice.available_domains()
    correct_values = [RaplPackageDomain(0), RaplDramDomain(0), RaplPackageDomain(1), RaplDramDomain(1)]
    assert sorted(correct_values) == sorted(returned_values)
Example #11
0
def test_available_domains_with_pkg_uncore_and_dram_rapl_api_return_correct_values(fs_pkg_dram_uncore_one_socket):
    returned_values = RaplDevice.available_domains()
    correct_values = [RaplPackageDomain(0), RaplDramDomain(0), RaplUncoreDomain(0)]
    assert sorted(correct_values) == sorted(returned_values)
Example #12
0
def test_get_configured_domains_with_default_values_on_pkg_dram_rapl_api_return_correct_values(fs_pkg_dram_one_socket):
    configured_domains = [RaplPackageDomain(0), RaplDramDomain(0)]
    device = RaplDevice()
    device.configure()
    assert configured_domains == device.get_configured_domains()
Example #13
0
def test_dram_get_device_type_return_RaplDevice():
    domain = RaplDramDomain(0)
    assert domain.get_device_type() == RaplDevice
Example #14
0
def test_dram_repr_return_dram_underscore_socket_id(integer_value):
    domain = RaplDramDomain(integer_value)
    assert str(domain) == 'dram_' + str(integer_value)