From aca23ecb0bc7302036fb581c028018c1c28de6b8 Mon Sep 17 00:00:00 2001 From: "Bill(Shuzhou) Liu" Date: Wed, 26 Jul 2023 15:28:18 -0500 Subject: [PATCH] Handle csv output when the command is not based on the device Fix the error only one csv line can be printed out when output is not based on device. Change-Id: Idacc5d98acc223e932fb3d46c888bfa04778b73c [ROCm/rocm_smi_lib commit: 80d650b95a1db443d76c7fb644861f99110ca996] --- .../rocm-smi-lib/python_smi_tools/rocm_smi.py | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/projects/rocm-smi-lib/python_smi_tools/rocm_smi.py b/projects/rocm-smi-lib/python_smi_tools/rocm_smi.py index e374bd3e20..95f7e2510f 100755 --- a/projects/rocm-smi-lib/python_smi_tools/rocm_smi.py +++ b/projects/rocm-smi-lib/python_smi_tools/rocm_smi.py @@ -112,19 +112,10 @@ def formatCsv(deviceList): if outputType == 'system': jsonobj = json.loads(jsondata) keylist = header - for record in jsonobj: - my_string += str(record) - for key in keylist: - if key == 'system': - tempstr = str(jsonobj[record]) - tempstr = tempstr[tempstr.find('\'')+1:] - tempstr = tempstr[:tempstr.find('\'')] - # Force output device type to 'system' - my_string += ',%s\nsystem,%s' % (tempstr, jsonobj[record][tempstr]) - my_string += '\n' - # Force output device type to 'system' - if my_string.startswith('system'): - my_string = 'device' + my_string[6:] + for record in jsonobj['system']: + my_string += "\"%s\", \"%s\"\n" % (record, jsonobj['system'][record]) + # add header + my_string = "name, value\n" + my_string return my_string headerkeys = [] # Separate device-specific information from system-level information