From a21208fc4e8af142fcef0f77a91e8d6a734d0867 Mon Sep 17 00:00:00 2001 From: Ori Messinger Date: Mon, 21 Mar 2022 06:21:21 -0400 Subject: [PATCH] ROCm SMI CLI: Fix formatCsv Bug Fixes a bug in the 'formatCsv' function which mishandles json data conversion for 'system' data types. Signed-off-by: Ori Messinger Change-Id: I705060409bf5ae75b994ffda270843065ca12321 [ROCm/amdsmi commit: e800cbf161b325dba4011a79672688fcd1bad9f4] --- projects/amdsmi/python_smi_tools/rocm_smi.py | 34 ++++++++++++++++++-- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/projects/amdsmi/python_smi_tools/rocm_smi.py b/projects/amdsmi/python_smi_tools/rocm_smi.py index d9606c01da..056ab2fbd8 100755 --- a/projects/amdsmi/python_smi_tools/rocm_smi.py +++ b/projects/amdsmi/python_smi_tools/rocm_smi.py @@ -96,8 +96,33 @@ def formatCsv(deviceList): """ Print out the JSON_DATA in CSV format """ global JSON_DATA jsondata = json.dumps(JSON_DATA) - - header = ['device'] + outstr = jsondata + # Check if the first json data element is 'system' or 'device' + outputType = outstr[outstr.find('\"')+1:] + outputType = outputType[:outputType.find('\"')] + header = [] + my_string = '' + if outputType != 'system': + header.append('device') + else: + header.append('system') + 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:] + return my_string headerkeys = [] # Separate device-specific information from system-level information for dev in deviceList: @@ -110,7 +135,10 @@ def formatCsv(deviceList): if len(header) <= 1: return '' for dev in deviceList: - outStr += 'card%s,' % dev + if str(dev) != 'system': + outStr += 'card%s,' % dev + else: + outStr += 'system,' for val in headerkeys: try: if str(dev) != 'system':