ROCm SMI Python CLI: Fix printLog Collisions
Python's default 'print' implementation is not thread safe, causing empty lines to be printed during multithreaded code execution. This fixes the --showevents output for multi-GPU systems. Signed-off-by: Ori Messinger <Ori.Messinger@amd.com> Change-Id: I72f7341cdf4401f1fed4cd8f7d7a4a90bf9a3a4c
This commit is contained in:
committed by
Bill(Shuzhou) Liu
szülő
034caf6f76
commit
8d5ced1f60
@@ -440,7 +440,6 @@ def printEventList(device, delay, eventList):
|
|||||||
@param delay: Notification delay in ms
|
@param delay: Notification delay in ms
|
||||||
@param eventList: List of event type names (can be a single-item list)
|
@param eventList: List of event type names (can be a single-item list)
|
||||||
"""
|
"""
|
||||||
print2DArray([['DEVICE\t', 'TIME\t', 'TYPE\t', 'DESCRIPTION']])
|
|
||||||
mask = 0
|
mask = 0
|
||||||
ret = rocmsmi.rsmi_event_notification_init(device)
|
ret = rocmsmi.rsmi_event_notification_init(device)
|
||||||
if not rsmi_ret_ok(ret, device):
|
if not rsmi_ret_ok(ret, device):
|
||||||
@@ -483,7 +482,8 @@ def printLog(device, metricName, value):
|
|||||||
if device is None:
|
if device is None:
|
||||||
logstr = logstr[13:]
|
logstr = logstr[13:]
|
||||||
logging.debug(logstr)
|
logging.debug(logstr)
|
||||||
print(logstr)
|
# Force thread safe printing
|
||||||
|
print(logstr + '\n\r', end='')
|
||||||
|
|
||||||
|
|
||||||
def printListLog(metricName, valuesList):
|
def printListLog(metricName, valuesList):
|
||||||
@@ -2129,7 +2129,9 @@ def showEvents(deviceList, eventTypes):
|
|||||||
printErrLog(None, 'Ignoring unrecognized event type %s' % (event.replace(',', '')))
|
printErrLog(None, 'Ignoring unrecognized event type %s' % (event.replace(',', '')))
|
||||||
if len(eventTypeList) == 0:
|
if len(eventTypeList) == 0:
|
||||||
eventTypeList = notification_type_names
|
eventTypeList = notification_type_names
|
||||||
try: # Create a seperate thread for each GPU
|
try:
|
||||||
|
print2DArray([['DEVICE\t', 'TIME\t', 'TYPE\t', 'DESCRIPTION']])
|
||||||
|
# Create a seperate thread for each GPU
|
||||||
for device in deviceList:
|
for device in deviceList:
|
||||||
_thread.start_new_thread(printEventList, (device, 1000, eventTypeList))
|
_thread.start_new_thread(printEventList, (device, 1000, eventTypeList))
|
||||||
time.sleep(0.25)
|
time.sleep(0.25)
|
||||||
|
|||||||
Reference in New Issue
Block a user