From e5a245ff0018dbdeb885cbea2adeeaf2cc6b4b75 Mon Sep 17 00:00:00 2001 From: Ori Messinger Date: Thu, 17 Dec 2020 04:44:41 -0500 Subject: [PATCH] ROCm SMI Python CLI: Add Json Functionality to showPids The purpose of this patch is to add Json functionality to showPids by modifying the print2DArray function to use printSysLog. Change-Id: Ie834d209b29332777c3f13f776f81c37d94b01b6 Signed-off-by: Ori Messinger [ROCm/rocm_smi_lib commit: d9da4902142520e494363d0a52d8bfcabcca6f48] --- .../rocm-smi-lib/python_smi_tools/rocm_smi.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 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 1fdb0ba479..cfab54bc8b 100755 --- a/projects/rocm-smi-lib/python_smi_tools/rocm_smi.py +++ b/projects/rocm-smi-lib/python_smi_tools/rocm_smi.py @@ -377,8 +377,11 @@ def getVersion(deviceList, component): def print2DArray(dataArray): """ Print 2D Array with uniform spacing """ - # TODO: Add --json/--csv support + global PRINT_JSON dataArrayLength = [] + isPid = False + if str(dataArray[0][0]) == 'PID': + isPid = True for position in range(len(dataArray[0])): dataArrayLength.append(len(dataArray[0][position])) for position in range(len(dataArray)): @@ -389,7 +392,18 @@ def print2DArray(dataArray): printString = '' for cell in range(len(dataArray[0])): printString += str(dataArray[position][cell]).ljust(dataArrayLength[cell], ' ') + '\t' - printLog(None, printString, None) + if PRINT_JSON: + printString = ' '.join(printString.split()).lower() + firstElement = printString.split(' ', 1)[0] + printString = printString.split(' ', 1)[1] + printString = printString.replace(' ', ', ') + if (position > 0): + if isPid: + printSysLog('PID%s' % (firstElement), printString) + else: + printSysLog(firstElement, printString) + else: + printLog(None, printString, None) def printEmptyLine():