[SWDEV-534745] Generate valid json output for xgmi command
The amd-smi xgmi --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>
This commit is contained in:
committed by
Arif, Maisam
vanhempi
fab13c5b60
commit
8f943b03e1
@@ -6055,7 +6055,11 @@ class AMDSMICommands():
|
||||
new_output.append(self.logger.flatten_dict(elem, topology_override=True))
|
||||
self.logger.multiple_device_output = new_output
|
||||
|
||||
if not self.logger.is_human_readable_format():
|
||||
if self.logger.is_json_format():
|
||||
self.logger.store_xgmi_metric_json_output.append(xgmi_values)
|
||||
if not args.link_status:
|
||||
self.logger.combine_arrays_to_json()
|
||||
elif not self.logger.is_human_readable_format():
|
||||
self.logger.print_output(multiple_device_enabled=True)
|
||||
|
||||
if args.link_status:
|
||||
@@ -6086,6 +6090,8 @@ class AMDSMICommands():
|
||||
else:
|
||||
del tabular_output_dict['gpu#']
|
||||
tabular_output.append(tabular_output_dict)
|
||||
if self.logger.is_json_format():
|
||||
self.logger.store_xgmi_link_status_json_output.append(tabular_output_dict)
|
||||
except amdsmi_exception.AmdSmiLibraryException as e:
|
||||
xgmi_dict['link_metrics']['link_status']={"status": "failed"}
|
||||
logging.debug("Failed to get XGMI link status for GPU %s | %s", src_gpu_id, e.get_error_info())
|
||||
@@ -6095,8 +6101,11 @@ class AMDSMICommands():
|
||||
xgmi_dict['link_status'] = tabular_output
|
||||
self.logger.multiple_device_output= tabular_output
|
||||
self.logger.table_title = "\nXGMI LINK STATUS"
|
||||
self.logger.print_output(multiple_device_enabled=True, tabular=True)
|
||||
if not self.logger.is_json_format():
|
||||
self.logger.print_output(multiple_device_enabled=True, tabular=True)
|
||||
self.logger.clear_multiple_devices_output()
|
||||
if self.logger.is_json_format():
|
||||
self.logger.combine_arrays_to_json()
|
||||
if self.logger.is_human_readable_format():
|
||||
# Populate the legend output
|
||||
legend_parts = [
|
||||
|
||||
@@ -46,6 +46,8 @@ class AMDSMILogger():
|
||||
self.store_cpu_json_output = []
|
||||
self.store_core_json_output = []
|
||||
self.store_gpu_json_output = []
|
||||
self.store_xgmi_metric_json_output = []
|
||||
self.store_xgmi_link_status_json_output = []
|
||||
|
||||
|
||||
class LoggerFormat(Enum):
|
||||
@@ -576,11 +578,18 @@ class AMDSMILogger():
|
||||
|
||||
|
||||
def combine_arrays_to_json(self):
|
||||
combined_json = {
|
||||
"cpu_data": self.store_cpu_json_output,
|
||||
"core_data": self.store_core_json_output,
|
||||
"gpu_data": self.store_gpu_json_output
|
||||
}
|
||||
combined_json = {}
|
||||
if self.store_cpu_json_output:
|
||||
combined_json["cpu_data"] = self.store_cpu_json_output
|
||||
if self.store_core_json_output:
|
||||
combined_json["core_data"] = self.store_core_json_output
|
||||
if self.store_gpu_json_output:
|
||||
combined_json["gpu_data"] = self.store_gpu_json_output
|
||||
if self.store_xgmi_metric_json_output:
|
||||
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
|
||||
|
||||
self.destination == 'stdout'
|
||||
json_std_output = json.dumps(combined_json, indent=4)
|
||||
print(json_std_output)
|
||||
|
||||
Viittaa uudesa ongelmassa
Block a user