[SWDEV-530385] show afids on each line of printout (#422)

* show afids on each line of printout
* clean up afids and cper code
---------

Signed-off-by: Maisam Arif <Maisam.Arif@amd.com>
Co-authored-by: Maisam Arif <Maisam.Arif@amd.com>
This commit is contained in:
Saeed, Oosman
2025-06-02 17:22:10 -05:00
committed by GitHub
parent 91021da055
commit fab13c5b60
7 changed files with 107 additions and 197 deletions
+4 -1
View File
@@ -6476,7 +6476,10 @@ class AMDSMICommands():
args.gpu = self.device_handles
if args.afid and args.cper_file:
self.helpers.pvtDumpAfids(args.cper_file)
afids = self.helpers.pvtDumpAfids(args.cper_file)
for afid in afids:
print(afid, end=" ")
print("")
return
if not self.group_check_printed:
+13 -18
View File
@@ -1096,7 +1096,7 @@ class AMDSMIHelpers():
# Header
print(f"{'timestamp':<20} {'gpu_id':<7} {'severity':<12}", end="")
if folder:
print(f" {'file_name':<17}", end="")
print(f" {'file_name':<17} {'afid'}", end="")
print("")
self._cper_display_initialized = True
@@ -1122,13 +1122,19 @@ class AMDSMIHelpers():
print(f"{timestamp:<20} {gpu_id:<7} {prefix:<12}", end="")
if folder:
print(f" {cper_data_file:<17}", end="")
afids = self.pvtDumpAfids(cper_data_file)
for afid in afids:
print(afid, end=" ")
print("")
self.increment_cper_count()
def dump_cper_entries(self, folder, entries, cper_data, device_handle, file_limit=None):
# Onetime header
if not getattr(self, "_cper_display_initialized", False):
print(f"{'timestamp':<20} {'gpu_id':<7} {'severity':<12} {'file_name':<17}")
print(f"{'timestamp':<20} {'gpu_id':<7} {'severity':<12} ", end="")
if folder:
print(f"{'file_name':<17} {'afid'}", end="")
print("")
self._cper_display_initialized = True
if folder:
@@ -1201,7 +1207,9 @@ class AMDSMIHelpers():
to_print = printed_rows
for ts, gid, prefix, fname in to_print:
print(f"{ts:<20} {gid:<7} {prefix:<12} {fname:<17}")
cper_path = folder / cper_name
afids = self.pvtDumpAfids(cper_path)
print(f"{ts:<20} {gid:<7} {prefix:<12} {fname:<17} {afids}")
else:
print(json.dumps(
@@ -1278,13 +1286,9 @@ class AMDSMIHelpers():
else:
# assume it's already bytes
raw = raw_data
size = len(raw)
self.hexdump_to_string(raw)
afids, num_afids = amdsmi_interface.amdsmi_get_afids_from_cper(raw)
print(f"AFIDS: ", end="")
for afid in afids:
print(afid, end=" ")
print("")
return afids
def ras_cper(self, args, device_handle, logger, gpu_idx):
# Parse severity mask dynamically from the --severity option.
@@ -1351,16 +1355,7 @@ class AMDSMIHelpers():
if len(entries) == 0:
break
if args.folder:
if args.follow:
if device_handle:
self.dump_cper_entries(args.folder, entries, cper_data, device_handle, args.file_limit)
else:
self.dump_cper_entries(args.folder, entries, cper_data, device_handle, args.file_limit)
else:
if device_handle:
self.dump_cper_entries(args.folder, entries, cper_data, device_handle, args.file_limit)
else:
self.dump_cper_entries(args.folder, entries, cper_data, device_handle, args.file_limit)
self.dump_cper_entries(args.folder, entries, cper_data, device_handle, args.file_limit)
break
else:
self.display_cper_files_generated(entries, device_handle, args.folder, args.follow)
+14 -15
View File
@@ -304,26 +304,25 @@ class AMDSMIParser(argparse.ArgumentParser):
def _check_cper_file_path(self):
""" Argument action validator:
Returns a path to a file from the input file path provided.
If the file doesn't exist or is empty raise error
If the file doesn't exist, is empty, or is invalid, raise an error.
"""
class _CheckInputFilePath(argparse.Action):
# Checks the values
def __call__(self, parser, args, values, option_string=None):
path = Path(values)
if not path.exists():
raise FileNotFoundError(f"CPER file could not be read. Make sure the path '{path}' is correct. ")
if path.is_dir():
raise argparse.ArgumentTypeError(
f"Invalid Path: {path} is directory when it needs to be a specific file")
if path.is_file():
if os.stat(values).st_size == 0:
raise argparse.ArgumentTypeError(f"Invalid Path: {path} Input file is empty")
setattr(args, self.dest, path)
else:
raise argparse.ArgumentTypeError(
f"Invalid path:{path} Could not determine if value given is a valid path")
try:
if not path.exists():
raise FileNotFoundError(f"CPER file could not be read. Make sure the path '{path}' is correct.")
if path.is_dir():
raise IsADirectoryError(f"Invalid Path: {path} is a directory when it needs to be a specific file.")
if path.is_file():
if os.stat(values).st_size == 0:
raise ValueError(f"Invalid Path: {path} Input file is empty.")
setattr(args, self.dest, path)
else:
raise FileNotFoundError(f"Invalid Path: {path} Could not determine if the value given is a valid path.")
except Exception as root_cause:
raise amdsmi_cli_exceptions.AmdSmiInvalidFilePathException(path, _CheckInputFilePath.outputformat) from root_cause
return _CheckInputFilePath