3434from diagnostic_msgs .msg import DiagnosticArray , DiagnosticStatus , KeyValue
3535import rospy
3636
37- from computer_hw .gpu_util import Nvidia_GPU_Stat
37+ from computer_hw .gpu_util import GPUStatusHandler
3838
3939
4040class NVidiaTempMonitor (object ):
@@ -55,7 +55,7 @@ def gpu_status_to_diag(gpu_stat):
5555 stat .values .append (KeyValue (key = 'Display' , value = gpu_stat .display ))
5656 stat .values .append (KeyValue (key = 'Driver Version' , value = gpu_stat .driver_version ))
5757 stat .values .append (KeyValue (key = 'Temperature (C)' , value = '%.0f' % gpu_stat .temperature ))
58- stat .values .append (KeyValue (key = 'Fan Speed (RPM)' , value = '%.0f' % _rads_to_rpm (gpu_stat .fan_speed )))
58+ stat .values .append (KeyValue (key = 'Fan Speed (RPM)' , value = '%.0f' % GPUStatusHandler . rads_to_rpm (gpu_stat .fan_speed )))
5959 stat .values .append (KeyValue (key = 'Usage (%)' , value = '%.0f' % gpu_stat .gpu_usage ))
6060 stat .values .append (KeyValue (key = 'Memory (%)' , value = '%.0f' % gpu_stat .memory_usage ))
6161
@@ -111,33 +111,33 @@ def pub_status(self):
111111def parse_smi_output (output ):
112112 gpu_stat = GPUStatus ()
113113
114- gpu_stat .product_name = _find_val (output , 'Product Name' )
115- gpu_stat .pci_device_id = _find_val (output , 'PCI Device/Vendor ID' )
116- gpu_stat .pci_location = _find_val (output , 'PCI Location ID' )
117- gpu_stat .display = _find_val (output , 'Display' )
118- gpu_stat .driver_version = _find_val (output , 'Driver Version' )
114+ gpu_stat .product_name = GPUStatusHandler . _find_val (output , 'Product Name' )
115+ gpu_stat .pci_device_id = GPUStatusHandler . _find_val (output , 'PCI Device/Vendor ID' )
116+ gpu_stat .pci_location = GPUStatusHandler . _find_val (output , 'PCI Location ID' )
117+ gpu_stat .display = GPUStatusHandler . _find_val (output , 'Display' )
118+ gpu_stat .driver_version = GPUStatusHandler . _find_val (output , 'Driver Version' )
119119
120120 TEMPERATURE_QUERIES = ["Temperature" , "GPU Current Temp" ]
121121 for query in TEMPERATURE_QUERIES :
122- temp_str = _find_val (output , query )
122+ temp_str = GPUStatusHandler . _find_val (output , query )
123123 if temp_str :
124- temp , units = temp_str .split ()
124+ temp = temp_str .split ()[ 0 ]
125125 gpu_stat .temperature = int (temp )
126126 break
127127
128- fan_str = _find_val (output , 'Fan Speed' )
128+ fan_str = GPUStatusHandler . _find_val (output , 'Fan Speed' )
129129 if fan_str :
130130 # Fan speed in RPM
131- fan_spd = float (fan_str .strip ('\%' ).strip ()) * 0.01 * MAX_FAN_RPM
131+ fan_spd = float (fan_str .strip ('\%' ).strip ()) * 0.01 * GPUStatusHandler . _MAX_FAN_RPM
132132 # Convert fan speed to Hz
133- gpu_stat .fan_speed = _rpm_to_rads (fan_spd )
133+ gpu_stat .fan_speed = GPUStatusHandler . rpm_to_rads (fan_spd )
134134
135- usage_str = _find_val (output , 'GPU' )
135+ usage_str = GPUStatusHandler . _find_val (output , 'GPU' )
136136 if usage_str :
137137 usage = usage_str .strip ('\%' ).strip ()
138138 gpu_stat .gpu_usage = int (usage )
139139
140- mem_str = _find_val (output , 'Memory' )
140+ mem_str = GPUStatusHandler . _find_val (output , 'Memory' )
141141 if mem_str :
142142 mem = mem_str .strip ('\%' ).strip ()
143143 gpu_stat .memory_usage = int (mem )
0 commit comments