Пример #1
0
class Monitoring:
    "Generic class for monitoring"

    def __init__(self):
        self.mon = PqosMon()
        self.groups = []

    def setup_groups(self):
        "Sets up monitoring groups. Needs to be implemented by a derived class."

        return []

    def setup(self):
        "Resets monitoring and configures (starts) monitoring groups."

        self.mon.reset()
        self.groups = self.setup_groups()

    def update(self):
        "Updates values for monitored events."

        self.mon.poll(self.groups)

    def print_data(self):
        """Prints current values for monitored events. Needs to be implemented
        by a derived class."""

        pass

    def stop(self):
        "Stops monitoring."

        for group in self.groups:
            group.stop()
Пример #2
0
    def test_start(self, lib):
        "Tests start() method."

        values = CPqosEventValues(llc=123, mbm_local=456, mbm_total=789,
                                  mbm_remote=120, mbm_local_delta=456,
                                  mbm_total_delta=789, mbm_remote_delta=120)
        group_mock = CPqosMonData(values=values)

        def pqos_mon_start_mock(num_cores, cores_arr, event, _context,
                                group_ref):
            "Mock pqos_mon_start()."

            self.assertEqual(num_cores, 2)
            self.assertEqual(cores_arr[0], 1)
            self.assertEqual(cores_arr[1], 3)
            exp_event = CPqosMonitor.PQOS_MON_EVENT_L3_OCCUP
            exp_event |= CPqosMonitor.PQOS_MON_EVENT_LMEM_BW
            self.assertEqual(event, exp_event)
            ctypes.memmove(group_ref, ctypes.addressof(group_mock),
                           ctypes.sizeof(group_mock))
            return 0

        func_mock = MagicMock(side_effect=pqos_mon_start_mock)
        lib.pqos_mon_start = func_mock

        mon = PqosMon()
        group = mon.start([1, 3], ['l3_occup', 'lmem_bw'])

        lib.pqos_mon_start.assert_called_once()

        self.assertEqual(group.values.llc, 123)
        self.assertEqual(group.values.mbm_local, 456)
Пример #3
0
    def test_poll(self, lib):
        "Tests poll() method."
        values = CPqosEventValues(llc=678, mbm_local=653, mbm_total=721,
                                  mbm_remote=68, mbm_local_delta=653,
                                  mbm_total_delta=721, mbm_remote_delta=68,
                                  ipc=0.98, llc_misses=10, llc_misses_delta=10)
        event = CPqosMonitor.PQOS_MON_EVENT_L3_OCCUP
        group = CPqosMonData(event=event, values=values)

        values2 = CPqosEventValues(llc=998, mbm_local=653, mbm_total=721,
                                   mbm_remote=68, mbm_local_delta=653,
                                   mbm_total_delta=721, mbm_remote_delta=68,
                                   ipc=0.98, llc_misses=10, llc_misses_delta=10)
        group_mock2 = CPqosMonData(values=values2)

        def pqos_mon_poll_mock(groups_arr, num_groups):
            "Mock pqos_mon_poll()."

            self.assertEqual(num_groups, 1)
            ctypes.memmove(groups_arr[0], ctypes.addressof(group_mock2),
                           ctypes.sizeof(group_mock2))
            return 0

        func_mock = MagicMock(side_effect=pqos_mon_poll_mock)
        lib.pqos_mon_poll = func_mock

        mon = PqosMon()
        mon.poll([group])

        lib.pqos_mon_poll.assert_called_once()

        self.assertEqual(group.values.llc, 998)
Пример #4
0
    def test_start_pids(self, lib):
        "Tests start_pids() method."
        values = CPqosEventValues(llc=678, mbm_local=653, mbm_total=721,
                                  mbm_remote=68, mbm_local_delta=653,
                                  mbm_total_delta=721, mbm_remote_delta=68,
                                  ipc=0.98, llc_misses=10, llc_misses_delta=10)
        group_mock = CPqosMonData(values=values)

        def pqos_mon_start_pids_mock(num_pids, pids_arr, event, _context,
                                     group_ref):
            "Mock pqos_mon_start_pids()."

            self.assertEqual(num_pids, 2)
            self.assertEqual(pids_arr[0], 1286)
            self.assertEqual(pids_arr[1], 2251)
            exp_event = CPqosMonitor.PQOS_MON_EVENT_L3_OCCUP
            exp_event |= CPqosMonitor.PQOS_MON_EVENT_TMEM_BW
            self.assertEqual(event, exp_event)
            ctypes.memmove(group_ref, ctypes.addressof(group_mock),
                           ctypes.sizeof(group_mock))
            return 0

        func_mock = MagicMock(side_effect=pqos_mon_start_pids_mock)
        lib.pqos_mon_start_pids = func_mock

        mon = PqosMon()
        group = mon.start_pids([1286, 2251], ['l3_occup', 'tmem_bw'])

        lib.pqos_mon_start_pids.assert_called_once()

        self.assertEqual(group.values.llc, 678)
        self.assertEqual(group.values.mbm_local, 653)
        self.assertAlmostEqual(group.values.ipc, 0.98, places=5)
Пример #5
0
    def test_reset(self, lib):
        "Tests reset() method."
        # pylint: disable=no-self-use

        def pqos_mon_reset_mock():
            "Mock pqos_mon_reset()."

            return 0

        func_mock = MagicMock(side_effect=pqos_mon_reset_mock)
        lib.pqos_mon_reset = func_mock

        mon = PqosMon()
        mon.reset()

        lib.pqos_mon_reset.assert_called_once()
Пример #6
0
    def test_assoc_get(self, lib):
        "Tests assoc_get() method."

        def pqos_mon_assoc_get_mock(core, rmid_ref):
            "Mock pqos_mon_assoc_get()."

            self.assertEqual(core, 3)
            ctypes_ref_set_uint(rmid_ref, 7)
            return 0

        func_mock = MagicMock(side_effect=pqos_mon_assoc_get_mock)
        lib.pqos_mon_assoc_get = func_mock

        mon = PqosMon()
        rmid = mon.assoc_get(3)

        self.assertEqual(rmid, 7)

        lib.pqos_mon_assoc_get.assert_called_once()
Пример #7
0
 def __init__(self):
     self.mon = PqosMon()
     self.groups = []