[SWDEV-534746] Generate valid json output for partition command

The amd-smi partition --json output was not in valid json
format. Changes are done to get the output in valid
json format.

Signed-off-by: Bindhiya Kanangot Balakrishnan <Bindhiya.KanangotBalakrishnan@amd.com>


[ROCm/amdsmi commit: 872c58b7a3]
This commit is contained in:
Bindhiya Kanangot Balakrishnan
2025-06-04 14:52:27 -05:00
committed by Arif, Maisam
szülő 99df131155
commit 60a86179b9
2 fájl változott, egészen pontosan 45 új sor hozzáadva és 14 régi sor törölve
@@ -6200,7 +6200,12 @@ class AMDSMICommands():
self.logger.multiple_device_output = tabular_output
self.logger.table_title = "CURRENT_PARTITION"
self.logger.print_output(multiple_device_enabled=True, tabular=True, dynamic=True)
if self.logger.is_json_format():
self.logger.store_current_partition_json_output.extend(tabular_output)
if not (args.memory or args.accelerator):
self.logger.combine_arrays_to_json()
else:
self.logger.print_output(multiple_device_enabled=True, tabular=True, dynamic=True)
self.logger.clear_multiple_devices_output()
###########################################
@@ -6232,7 +6237,12 @@ class AMDSMICommands():
self.logger.multiple_device_output = tabular_output
self.logger.table_title = "\nMEMORY_PARTITION"
self.logger.print_output(multiple_device_enabled=True, tabular=True, dynamic=True)
if self.logger.is_json_format():
self.logger.store_memory_partition_json_output.extend(tabular_output)
if not args.accelerator:
self.logger.combine_arrays_to_json()
else:
self.logger.print_output(multiple_device_enabled=True, tabular=True, dynamic=True)
self.logger.clear_multiple_devices_output()
###########################################
@@ -6381,7 +6391,10 @@ class AMDSMICommands():
** Please run the command with sudo permissions to get accurate results. **
***************************************************************************
"""
self.logger.print_output(multiple_device_enabled=True, tabular=True, dynamic=True)
if self.logger.is_json_format():
self.logger.store_partition_profiles_json_output.extend(tabular_output)
else:
self.logger.print_output(multiple_device_enabled=True, tabular=True, dynamic=True)
self.logger.clear_multiple_devices_output()
self.logger.warning_message = "" # clear the warning message
@@ -6430,19 +6443,25 @@ class AMDSMICommands():
self.logger.multiple_device_output = tabular_output
self.logger.table_title = "\nACCELERATOR_PARTITION_RESOURCES"
self.logger.print_output(multiple_device_enabled=True, tabular=True, dynamic=True)
if self.logger.is_json_format():
self.logger.store_partition_resources_json_output.extend(tabular_output)
else:
self.logger.print_output(multiple_device_enabled=True, tabular=True, dynamic=True)
if self.logger.is_json_format():
self.logger.combine_arrays_to_json()
self.logger.clear_multiple_devices_output()
# print legend
legend_parts = [
"\n\nLegend:",
" * = Current mode"]
legend_output = "\n".join(legend_parts)
if self.logger.destination == 'stdout':
print(legend_output)
else:
with self.logger.destination.open('a', encoding="utf-8") as output_file:
output_file.write(legend_output + '\n')
if not self.logger.is_json_format():
# print legend
legend_parts = [
"\n\nLegend:",
" * = Current mode"]
legend_output = "\n".join(legend_parts)
if self.logger.destination == 'stdout':
print(legend_output)
else:
with self.logger.destination.open('a', encoding="utf-8") as output_file:
output_file.write(legend_output + '\n')
def ras(self, args, multiple_devices=False, gpu=None, cper=None, afid=None,
@@ -48,6 +48,10 @@ class AMDSMILogger():
self.store_gpu_json_output = []
self.store_xgmi_metric_json_output = []
self.store_xgmi_link_status_json_output = []
self.store_current_partition_json_output = []
self.store_memory_partition_json_output = []
self.store_partition_profiles_json_output = []
self.store_partition_resources_json_output = []
class LoggerFormat(Enum):
@@ -589,6 +593,14 @@ class AMDSMILogger():
combined_json["xgmi_metric"] = self.store_xgmi_metric_json_output
if self.store_xgmi_link_status_json_output:
combined_json["link_status"] = self.store_xgmi_link_status_json_output
if self.store_current_partition_json_output:
combined_json["current_partition"] = self.store_current_partition_json_output
if self.store_memory_partition_json_output:
combined_json["memory_partition"] = self.store_memory_partition_json_output
if self.store_partition_profiles_json_output:
combined_json["partition_profiles"] = self.store_partition_profiles_json_output
if self.store_partition_resources_json_output:
combined_json["partition_resources"] = self.store_partition_resources_json_output
self.destination == 'stdout'
json_std_output = json.dumps(combined_json, indent=4)