Skip to content

Commit

Permalink
Merge pull request #378 from SpiNNakerManchester/cpu_infos
Browse files Browse the repository at this point in the history
infos_not_in_states method
  • Loading branch information
Christian-B authored Nov 2, 2023
2 parents ed7e091 + 11849b2 commit f50bb65
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
14 changes: 14 additions & 0 deletions spinnman/model/cpu_infos.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,20 @@ def infos_for_state(self, state: CPUState) -> 'CPUInfos':
for_state.add_info(info)
return for_state

def infos_not_in_states(self, states: Iterable[CPUState]) -> 'CPUInfos':
"""
Creates a new CpuInfos object with Just the Infos that match the state.
:param iterable(~spinnman.model.enums.CPUState) states:
:return: New Infos object with the filtered infos if any
:rtype: CPUInfos
"""
for_state = CPUInfos()
for info in self._cpu_infos.values():
if info.state not in states:
for_state.add_info(info)
return for_state

def get_status_string(self) -> str:
"""
Get a string indicating the status of the given cores.
Expand Down
9 changes: 5 additions & 4 deletions unittests/model_tests/test_cpu_infos.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,14 @@ def test_cpu_infos(self):
"['0, 0, 2 (ph: 6)', '1, 0, 1 (ph: 7)']", str(finished))
self.assertTrue(finished)

finished = infos.infos_not_in_states(
[CPUState.RUNNING, CPUState.RUN_TIME_EXCEPTION])
self.assertEqual(
"['0, 0, 2 (ph: 6)', '1, 0, 1 (ph: 7)']", str(finished))

idle = infos.infos_for_state(CPUState.IDLE)
self.assertFalse(idle)

info = infos.get_cpu_info(0, 0, 2)
self.assertEqual(
"0:0:02 (06) FINISHED scamp-3 0", str(info))

# the str is for example purpose and may change without notice
self.assertEqual(infos.get_status_string(),
"0:0:1 in state RUNNING\n"
Expand Down

0 comments on commit f50bb65

Please sign in to comment.