34
34
from diagnostic_msgs .msg import DiagnosticArray , DiagnosticStatus , KeyValue
35
35
import rospy
36
36
37
- from computer_hw .gpu_util import Nvidia_GPU_Stat
37
+ from computer_hw .gpu_util import GPUStatusHandler
38
38
39
39
40
40
class NVidiaTempMonitor (object ):
@@ -55,7 +55,7 @@ def gpu_status_to_diag(gpu_stat):
55
55
stat .values .append (KeyValue (key = 'Display' , value = gpu_stat .display ))
56
56
stat .values .append (KeyValue (key = 'Driver Version' , value = gpu_stat .driver_version ))
57
57
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 )))
59
59
stat .values .append (KeyValue (key = 'Usage (%)' , value = '%.0f' % gpu_stat .gpu_usage ))
60
60
stat .values .append (KeyValue (key = 'Memory (%)' , value = '%.0f' % gpu_stat .memory_usage ))
61
61
@@ -111,33 +111,33 @@ def pub_status(self):
111
111
def parse_smi_output (output ):
112
112
gpu_stat = GPUStatus ()
113
113
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' )
119
119
120
120
TEMPERATURE_QUERIES = ["Temperature" , "GPU Current Temp" ]
121
121
for query in TEMPERATURE_QUERIES :
122
- temp_str = _find_val (output , query )
122
+ temp_str = GPUStatusHandler . _find_val (output , query )
123
123
if temp_str :
124
- temp , units = temp_str .split ()
124
+ temp = temp_str .split ()[ 0 ]
125
125
gpu_stat .temperature = int (temp )
126
126
break
127
127
128
- fan_str = _find_val (output , 'Fan Speed' )
128
+ fan_str = GPUStatusHandler . _find_val (output , 'Fan Speed' )
129
129
if fan_str :
130
130
# 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
132
132
# 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 )
134
134
135
- usage_str = _find_val (output , 'GPU' )
135
+ usage_str = GPUStatusHandler . _find_val (output , 'GPU' )
136
136
if usage_str :
137
137
usage = usage_str .strip ('\%' ).strip ()
138
138
gpu_stat .gpu_usage = int (usage )
139
139
140
- mem_str = _find_val (output , 'Memory' )
140
+ mem_str = GPUStatusHandler . _find_val (output , 'Memory' )
141
141
if mem_str :
142
142
mem = mem_str .strip ('\%' ).strip ()
143
143
gpu_stat .memory_usage = int (mem )
0 commit comments