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()
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)