2323# SOFTWARE.
2424#
2525###############################################################################
26+ import re
2627from typing import Optional
2728
2829from nodescraper .base import InBandDataCollector
@@ -46,6 +47,12 @@ class RocmCollector(InBandDataCollector[RocmDataModel, None]):
4647 CMD_ROCM_VERSIONED_PATHS = "ls -v -d /opt/rocm-[3-7]* | tail -1"
4748 CMD_ROCM_ALL_PATHS = "ls -v -d /opt/rocm*"
4849
50+ @staticmethod
51+ def _strip_ansi_codes (text : str ) -> str :
52+ """Remove ANSI escape codes from text."""
53+ ansi_escape = re .compile (r"\x1b\[[0-9;]*m" )
54+ return ansi_escape .sub ("" , text )
55+
4956 def collect_data (self , args = None ) -> tuple [TaskResult , Optional [RocmDataModel ]]:
5057 """Collect ROCm version data from the system.
5158
@@ -63,28 +70,48 @@ def collect_data(self, args=None) -> tuple[TaskResult, Optional[RocmDataModel]]:
6370 if res .exit_code == 0 :
6471 rocm_data = RocmDataModel (rocm_version = res .stdout )
6572
66- # Collect rocminfo output
73+ # Collect rocminfo output as list of lines with ANSI codes stripped
6774 rocminfo_res = self ._run_sut_cmd (self .CMD_ROCMINFO )
6875 if rocminfo_res .exit_code == 0 :
69- rocm_data .rocminfo = rocminfo_res .stdout
76+ # Split into lines and strip ANSI codes from each line
77+ rocm_data .rocminfo = [
78+ self ._strip_ansi_codes (line )
79+ for line in rocminfo_res .stdout .strip ().split ("\n " )
80+ ]
7081
7182 # Collect latest versioned ROCm path (rocm-[3-7]*)
7283 versioned_path_res = self ._run_sut_cmd (self .CMD_ROCM_VERSIONED_PATHS )
7384 if versioned_path_res .exit_code == 0 :
74- rocm_data .rocm_latest_versioned_path = versioned_path_res .stdout
85+ rocm_data .rocm_latest_versioned_path = versioned_path_res .stdout . strip ()
7586
76- # Collect all ROCm paths
87+ # Collect all ROCm paths as list
7788 all_paths_res = self ._run_sut_cmd (self .CMD_ROCM_ALL_PATHS )
7889 if all_paths_res .exit_code == 0 :
79- rocm_data .rocm_all_paths = all_paths_res .stdout
90+ rocm_data .rocm_all_paths = [
91+ path .strip ()
92+ for path in all_paths_res .stdout .strip ().split ("\n " )
93+ if path .strip ()
94+ ]
95+
96+ # Create concise summary for logging
97+ log_summary = {
98+ "rocm_version" : rocm_data .rocm_version ,
99+ "rocminfo_lines_collected" : (
100+ len (rocm_data .rocminfo ) if rocm_data .rocminfo else 0
101+ ),
102+ "rocm_latest_versioned_path" : rocm_data .rocm_latest_versioned_path ,
103+ "rocm_paths_count" : (
104+ len (rocm_data .rocm_all_paths ) if rocm_data .rocm_all_paths else 0
105+ ),
106+ }
80107
81108 self ._log_event (
82109 category = "ROCM_VERSION_READ" ,
83110 description = "ROCm version data collected" ,
84- data = rocm_data . model_dump () ,
111+ data = log_summary ,
85112 priority = EventPriority .INFO ,
86113 )
87- self .result .message = f"ROCm: { rocm_data .model_dump () } "
114+ self .result .message = f"ROCm version : { rocm_data .rocm_version } , Latest path: { rocm_data . rocm_latest_versioned_path } "
88115 self .result .status = ExecutionStatus .OK
89116 break
90117 else :
0 commit comments