[SWDEV-520371] Generate valid json format output (#273)
Earlier, the amd-smi metric and static json output was not in valid json format. Changes are done to get the output in valid json format. --------- Change-Id: I5576333269509f63b3c800f225c3d73127ce80cf Signed-off-by: Bindhiya Kanangot Balakrishnan <Bindhiya.KanangotBalakrishnan@amd.com> Signed-off-by: Maisam Arif <Maisam.Arif@amd.com> Co-authored-by: Maisam Arif <Maisam.Arif@amd.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
b2f1df85a3
Коммит
8e5f6b1a8d
@@ -309,6 +309,8 @@ class AMDSMICommands():
|
||||
logging.debug(f"Static Arg information for CPU {cpu_id} on {self.helpers.os_info()}")
|
||||
|
||||
static_dict = {}
|
||||
if self.logger.is_json_format():
|
||||
static_dict['cpu'] = int(cpu_id)
|
||||
|
||||
if args.smu:
|
||||
try:
|
||||
@@ -329,11 +331,15 @@ class AMDSMICommands():
|
||||
logging.debug("Failed to get proto version for cpu %s | %s", cpu_id, e.get_error_info())
|
||||
|
||||
multiple_devices_csv_override = False
|
||||
self.logger.store_cpu_output(args.cpu, 'values', static_dict)
|
||||
if not self.logger.is_json_format():
|
||||
self.logger.store_cpu_output(args.cpu, 'values', static_dict)
|
||||
else:
|
||||
self.logger.store_cpu_json_output.append(static_dict)
|
||||
if multiple_devices:
|
||||
self.logger.store_multiple_device_output()
|
||||
return # Skip printing when there are multiple devices
|
||||
self.logger.print_output(multiple_device_enabled=multiple_devices_csv_override)
|
||||
if not self.logger.is_json_format():
|
||||
self.logger.print_output(multiple_device_enabled=multiple_devices_csv_override)
|
||||
|
||||
|
||||
def static_gpu(self, args, multiple_devices=False, gpu=None, asic=None, bus=None, vbios=None,
|
||||
@@ -452,6 +458,8 @@ class AMDSMICommands():
|
||||
|
||||
# Populate static dictionary for each enabled argument
|
||||
static_dict = {}
|
||||
if self.logger.is_json_format():
|
||||
static_dict['gpu'] = int(gpu_id)
|
||||
if args.asic:
|
||||
asic_dict = {
|
||||
"market_name" : "N/A",
|
||||
@@ -1016,14 +1024,20 @@ class AMDSMICommands():
|
||||
for key, value in ecc_block_dict.items():
|
||||
self.logger.store_output(args.gpu, key, value)
|
||||
self.logger.store_output(args.gpu, 'values', static_dict)
|
||||
self.logger.store_gpu_json_output.append(static_dict)
|
||||
self.logger.store_multiple_device_output()
|
||||
else:
|
||||
# Store values if ras has an error
|
||||
self.logger.store_output(args.gpu, 'values', static_dict)
|
||||
self.logger.store_gpu_json_output.append(static_dict)
|
||||
if self.helpers.is_linux() and self.helpers.is_virtual_os():
|
||||
self.logger.store_output(args.gpu, 'values', static_dict)
|
||||
self.logger.store_gpu_json_output.append(static_dict)
|
||||
else:
|
||||
self.logger.store_output(args.gpu, 'values', static_dict)
|
||||
self.logger.store_gpu_json_output.append(static_dict)
|
||||
elif self.logger.is_json_format():
|
||||
self.logger.store_gpu_json_output.append(static_dict)
|
||||
else:
|
||||
# Store values in logger.output
|
||||
self.logger.store_output(args.gpu, 'values', static_dict)
|
||||
@@ -1031,7 +1045,8 @@ class AMDSMICommands():
|
||||
if multiple_devices:
|
||||
self.logger.store_multiple_device_output()
|
||||
return # Skip printing when there are multiple devices
|
||||
self.logger.print_output(multiple_device_enabled=multiple_devices_csv_override)
|
||||
if not self.logger.is_json_format():
|
||||
self.logger.print_output(multiple_device_enabled=multiple_devices_csv_override)
|
||||
|
||||
|
||||
def static(self, args, multiple_devices=False, gpu=None, asic=None,
|
||||
@@ -1138,6 +1153,8 @@ class AMDSMICommands():
|
||||
board, numa, vram, cache, partition,
|
||||
dfc_ucode, fb_info, num_vf, soc_pstate, xgmi_plpd,
|
||||
process_isolation, clock)
|
||||
if self.logger.is_json_format():
|
||||
self.logger.combine_arrays_to_json()
|
||||
|
||||
|
||||
def firmware(self, args, multiple_devices=False, gpu=None, fw_list=True):
|
||||
@@ -1501,7 +1518,8 @@ class AMDSMICommands():
|
||||
args.gpu = stored_gpus
|
||||
|
||||
# Print multiple device output
|
||||
self.logger.print_output(multiple_device_enabled=True, watching_output=watching_output)
|
||||
if not self.logger.is_json_format():
|
||||
self.logger.print_output(multiple_device_enabled=True, watching_output=watching_output)
|
||||
|
||||
# Add output to total watch output and clear multiple device output
|
||||
if watching_output:
|
||||
@@ -1632,7 +1650,8 @@ class AMDSMICommands():
|
||||
"vram_max_bandwidth": "N/A",
|
||||
"xgmi_link_status": "N/A",
|
||||
}
|
||||
|
||||
if self.logger.is_json_format():
|
||||
values_dict['gpu'] = int(gpu_id)
|
||||
# Populate the pcie_dict first due to multiple gpu metrics calls incorrectly increasing bandwidth
|
||||
if "pcie" in current_platform_args:
|
||||
if args.pcie:
|
||||
@@ -2521,12 +2540,14 @@ class AMDSMICommands():
|
||||
if watching_output:
|
||||
self.logger.store_output(args.gpu, 'timestamp', int(time.time()))
|
||||
self.logger.store_output(args.gpu, 'values', values_dict)
|
||||
self.logger.store_gpu_json_output.append(values_dict)
|
||||
|
||||
if multiple_devices:
|
||||
self.logger.store_multiple_device_output()
|
||||
return # Skip printing when there are multiple devices
|
||||
|
||||
self.logger.print_output(watching_output=watching_output)
|
||||
if not self.logger.is_json_format():
|
||||
self.logger.print_output(watching_output=watching_output)
|
||||
|
||||
if watching_output: # End of single gpu add to watch_output
|
||||
self.logger.store_watch_output(multiple_device_enabled=False)
|
||||
@@ -2635,6 +2656,8 @@ class AMDSMICommands():
|
||||
logging.debug(f"Metric Arg information for CPU {cpu_id} on {self.helpers.os_info()}")
|
||||
|
||||
static_dict = {}
|
||||
if self.logger.is_json_format():
|
||||
static_dict['cpu'] = int(cpu_id)
|
||||
if args.cpu_power_metrics:
|
||||
static_dict["power_metrics"] = {}
|
||||
try:
|
||||
@@ -2817,11 +2840,15 @@ class AMDSMICommands():
|
||||
logging.debug("Failed to get dimm temperature range and refresh rate for cpu %s | %s", cpu_id, e.get_error_info())
|
||||
|
||||
multiple_devices_csv_override = False
|
||||
self.logger.store_cpu_output(args.cpu, 'values', static_dict)
|
||||
if not self.logger.is_json_format():
|
||||
self.logger.store_cpu_output(args.cpu, 'values', static_dict)
|
||||
else:
|
||||
self.logger.store_cpu_json_output.append(static_dict)
|
||||
if multiple_devices:
|
||||
self.logger.store_multiple_device_output()
|
||||
return # Skip printing when there are multiple devices
|
||||
self.logger.print_output(multiple_device_enabled=multiple_devices_csv_override)
|
||||
if not self.logger.is_json_format():
|
||||
self.logger.print_output(multiple_device_enabled=multiple_devices_csv_override)
|
||||
|
||||
|
||||
def metric_core(self, args, multiple_devices=False, core=None, core_boost_limit=None,
|
||||
@@ -2870,6 +2897,8 @@ class AMDSMICommands():
|
||||
logging.debug(f"Static Arg information for Core {core_id} on {self.helpers.os_info()}")
|
||||
|
||||
static_dict = {}
|
||||
if self.logger.is_json_format():
|
||||
static_dict['core'] = int(core_id)
|
||||
if args.core_boost_limit:
|
||||
static_dict["boost_limit"] ={}
|
||||
|
||||
@@ -2898,11 +2927,15 @@ class AMDSMICommands():
|
||||
logging.debug("Failed to get core energy for core %s | %s", core_id, e.get_error_info())
|
||||
|
||||
multiple_devices_csv_override = False
|
||||
self.logger.store_core_output(args.core, 'values', static_dict)
|
||||
if not self.logger.is_json_format():
|
||||
self.logger.store_core_output(args.core, 'values', static_dict)
|
||||
else:
|
||||
self.logger.store_core_json_output.append(static_dict)
|
||||
if multiple_devices:
|
||||
self.logger.store_multiple_device_output()
|
||||
return # Skip printing when there are multiple devices
|
||||
self.logger.print_output(multiple_device_enabled=multiple_devices_csv_override)
|
||||
if not self.logger.is_json_format():
|
||||
self.logger.print_output(multiple_device_enabled=multiple_devices_csv_override)
|
||||
|
||||
|
||||
def metric(self, args, multiple_devices=False, watching_output=False, gpu=None,
|
||||
@@ -3102,6 +3135,8 @@ class AMDSMICommands():
|
||||
fan, voltage_curve, overdrive, perf_level,
|
||||
xgmi_err, energy, mem_usage, schedule, throttle,
|
||||
)
|
||||
if self.logger.is_json_format():
|
||||
self.logger.combine_arrays_to_json()
|
||||
|
||||
|
||||
def process(self, args, multiple_devices=False, watching_output=False,
|
||||
|
||||
@@ -43,6 +43,9 @@ class AMDSMILogger():
|
||||
self.warning_message = ""
|
||||
self.helpers = AMDSMIHelpers()
|
||||
self._cper_exit_message = True
|
||||
self.store_cpu_json_output = []
|
||||
self.store_core_json_output = []
|
||||
self.store_gpu_json_output = []
|
||||
|
||||
|
||||
class LoggerFormat(Enum):
|
||||
@@ -565,6 +568,17 @@ class AMDSMILogger():
|
||||
json.dump(json_output, output_file, indent=4)
|
||||
|
||||
|
||||
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
|
||||
}
|
||||
self.destination == 'stdout'
|
||||
json_std_output = json.dumps(combined_json, indent=4)
|
||||
print(json_std_output)
|
||||
|
||||
|
||||
def _print_csv_output(self, multiple_device_enabled=False, watching_output=False):
|
||||
if multiple_device_enabled:
|
||||
stored_csv_output = self.multiple_device_output
|
||||
|
||||
@@ -1675,7 +1675,6 @@ def amdsmi_get_hsmp_metrics_table(
|
||||
"mtbl_socket_thm_residency_acc": mtbl.socket_thm_residency_acc,
|
||||
"mtbl_vr_thm_residency_acc": mtbl.vr_thm_residency_acc,
|
||||
"mtbl_hbm_thm_residency_acc": mtbl.hbm_thm_residency_acc,
|
||||
"mtbl_gfxclk_frequency": f"{[round(x*fraction_uq10 ,3) for x in list(mtbl.gfxclk_frequency)]} MHz"
|
||||
}
|
||||
|
||||
def amdsmi_first_online_core_on_cpu_socket(
|
||||
|
||||
Ссылка в новой задаче
Block a user