|
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):
|
@@ -111,33 +111,38 @@ 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 | + try: |
| 125 | + temp, units = temp_str.split() |
| 126 | + except ValueError as e: |
| 127 | + # Not sure but there seems to be a case where a single , |
| 128 | + # non-splittable value gets returned. |
| 129 | + temp = temp_str.split() |
125 | 130 | gpu_stat.temperature = int(temp)
|
126 | 131 | break
|
127 | 132 |
|
128 |
| - fan_str = _find_val(output, 'Fan Speed') |
| 133 | + fan_str = GPUStatusHandler._find_val(output, 'Fan Speed') |
129 | 134 | if fan_str:
|
130 | 135 | # Fan speed in RPM
|
131 |
| - fan_spd = float(fan_str.strip('\%').strip()) * 0.01 * MAX_FAN_RPM |
| 136 | + fan_spd = float(fan_str.strip('\%').strip()) * 0.01 * GPUStatusHandler.MAX_FAN_RPM |
132 | 137 | # Convert fan speed to Hz
|
133 | 138 | gpu_stat.fan_speed = _rpm_to_rads(fan_spd)
|
134 | 139 |
|
135 |
| - usage_str = _find_val(output, 'GPU') |
| 140 | + usage_str = GPUStatusHandler._find_val(output, 'GPU') |
136 | 141 | if usage_str:
|
137 | 142 | usage = usage_str.strip('\%').strip()
|
138 | 143 | gpu_stat.gpu_usage = int(usage)
|
139 | 144 |
|
140 |
| - mem_str = _find_val(output, 'Memory') |
| 145 | + mem_str = GPUStatusHandler._find_val(output, 'Memory') |
141 | 146 | if mem_str:
|
142 | 147 | mem = mem_str.strip('\%').strip()
|
143 | 148 | gpu_stat.memory_usage = int(mem)
|
|
0 commit comments