Skip to content

Commit

Permalink
move individual get_status_string into Cpu_info
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian-B committed Oct 3, 2023
1 parent 47e4e12 commit a56b228
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 22 deletions.
21 changes: 21 additions & 0 deletions spinnman/model/cpu_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,3 +329,24 @@ def __str__(self):
return "{}:{}:{:02n} ({:02n}) {:18} {:16s} {:3n}".format(
self.x, self.y, self.p, self.physical_cpu_id, self._state.name,
self._application_name, self._application_id)

def get_status_string(self):
"""
Get a string indicating the status of the given core.
:rtype: str
"""
if self.state == CPUState.RUN_TIME_EXCEPTION:
return (
f"{self._x}:{self._y}:{self._p} "
f"(ph: {self._physical_cpu_id}) "
f"in state {self._state.name}:{self._run_time_error.name}\n"
f" r0={self._registers[0]}, r1={self._registers[1]}, "
f"r2={self._registers[2]}, r3={self._registers[3]}\n"
f" r4={self._registers[4]}, r5={self._registers[5]}, "
f"r6={self._registers[6]}, r7={self._registers[7]}\n"
f" PSR={self._processor_state_register}, "
f"SP={self._stack_pointer}, LR={self._link_register}\n")
else:
return (
f"{self._x}:{self._y}:{self._p} in state {self._state.name}\n")
21 changes: 3 additions & 18 deletions spinnman/model/cpu_infos.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,24 +128,9 @@ def get_status_string(self):
:param CPUInfos cpu_infos: A CPUInfos objects
:rtype: str
"""
break_down = "\n"
for (x, y, p), core_info in self.cpu_infos:
if core_info.state == CPUState.RUN_TIME_EXCEPTION:
break_down += " {}:{}:{} (ph: {}) in state {}:{}\n".format(
x, y, p, core_info.physical_cpu_id, core_info.state.name,
core_info.run_time_error.name)
break_down += " r0={}, r1={}, r2={}, r3={}\n".format(
core_info.registers[0], core_info.registers[1],
core_info.registers[2], core_info.registers[3])
break_down += " r4={}, r5={}, r6={}, r7={}\n".format(
core_info.registers[4], core_info.registers[5],
core_info.registers[6], core_info.registers[7])
break_down += " PSR={}, SP={}, LR={}\n".format(
core_info.processor_state_register,
core_info.stack_pointer, core_info.link_register)
else:
break_down += " {}:{}:{} in state {}\n".format(
x, y, p, core_info.state.name)
break_down = ""
for core_info in self._cpu_infos.values():
break_down += core_info.get_status_string()
return break_down

def __str__(self):
Expand Down
16 changes: 12 additions & 4 deletions unittests/model_tests/test_cpu_infos.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,12 @@ def test_cpu_infos(self):
infos.add_info(info)
info = CPUInfo(1, 0, 1, self.make_info_data(7, CPUState.FINISHED))
infos.add_info(info)
info = CPUInfo(1, 1, 2, self.make_info_data(4, CPUState.RUN_TIME_EXCEPTION))
infos.add_info(info)

self.assertSetEqual(set(infos), {(1, 0, 1), (0, 0, 1), (0, 0, 2), (1, 1, 2)})
self.assertEqual(
"['0, 0, 1 (ph: 5)', '0, 0, 2 (ph: 6)', '1, 0, 1 (ph: 7)']",
"['0, 0, 1 (ph: 5)', '0, 0, 2 (ph: 6)', '1, 0, 1 (ph: 7)', '1, 1, 2 (ph: 4)']",
str(infos))

finished = infos.infos_for_state(CPUState.FINISHED)
Expand All @@ -60,9 +63,14 @@ def test_cpu_infos(self):
self.assertEqual(
"0:0:02 (06) FINISHED scamp-3 0", str(info))

a = set(infos)
b = str(a)
print(b)
self.assertEqual(infos.get_status_string(),
"0:0:1 in state RUNNING\n"
"0:0:2 in state FINISHED\n"
"1:0:1 in state FINISHED\n"
"1:1:2 (ph: 4) in state RUN_TIME_EXCEPTION:NONE\n"
" r0=134676544, r1=255, r2=8388608, r3=173\n"
" r4=0, r5=0, r6=0, r7=0\n"
" PSR=0, SP=0, LR=0\n")


if __name__ == '__main__':
Expand Down

0 comments on commit a56b228

Please sign in to comment.