mirror of https://github.com/aristocratos/bpytop
				
				
				
			Added try/except NotImplemented
title; Other cleanups Signed-off-by: Lucas Zampieri <lzampier@redhat.com>gpu
							parent
							
								
									fa3e61e911
								
							
						
					
					
						commit
						f3e7b522b1
					
				
							
								
								
									
										22
									
								
								bpytop.py
								
								
								
								
							
							
						
						
									
										22
									
								
								bpytop.py
								
								
								
								
							| 
						 | 
					@ -1665,7 +1665,7 @@ class Box:
 | 
				
			||||||
	bg: str
 | 
						bg: str
 | 
				
			||||||
	_b_cpu_h: int
 | 
						_b_cpu_h: int
 | 
				
			||||||
	_b_mem_h: int
 | 
						_b_mem_h: int
 | 
				
			||||||
	_b_proc_h: int
 | 
						_b_proc_h: int = 0
 | 
				
			||||||
	redraw_all: bool
 | 
						redraw_all: bool
 | 
				
			||||||
	buffers: List[str] = []
 | 
						buffers: List[str] = []
 | 
				
			||||||
	c_counter: int = 0
 | 
						c_counter: int = 0
 | 
				
			||||||
| 
						 | 
					@ -4113,7 +4113,7 @@ class GpuCollector(Collector):
 | 
				
			||||||
	gpu_brand: str = ""
 | 
						gpu_brand: str = ""
 | 
				
			||||||
	gpu_error: bool = False
 | 
						gpu_error: bool = False
 | 
				
			||||||
	reset: bool = False
 | 
						reset: bool = False
 | 
				
			||||||
 | 
						uuid: str = ""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	# * stats structure = stats[cardN]
 | 
						# * stats structure = stats[cardN]
 | 
				
			||||||
	# [fans, freqs, vitals, power, load]
 | 
						# [fans, freqs, vitals, power, load]
 | 
				
			||||||
| 
						 | 
					@ -4244,7 +4244,6 @@ class GpuCollector(Collector):
 | 
				
			||||||
			cls.gpu = cls.gpus[cls.gpu_i]
 | 
								cls.gpu = cls.gpus[cls.gpu_i]
 | 
				
			||||||
			cls.populated = True
 | 
								cls.populated = True
 | 
				
			||||||
		elif cls.gpu_brand == "NVIDIA":
 | 
							elif cls.gpu_brand == "NVIDIA":
 | 
				
			||||||
			nvml.nvmlInit()
 | 
					 | 
				
			||||||
			if nvml.nvmlDeviceGetCount() == 1:
 | 
								if nvml.nvmlDeviceGetCount() == 1:
 | 
				
			||||||
				cls.gpu = [cls.handle]
 | 
									cls.gpu = [cls.handle]
 | 
				
			||||||
				cls.name = nvml.nvmlDeviceGetName(cls.handle)
 | 
									cls.name = nvml.nvmlDeviceGetName(cls.handle)
 | 
				
			||||||
| 
						 | 
					@ -4267,8 +4266,11 @@ class GpuCollector(Collector):
 | 
				
			||||||
			for (i, name) in cls.stat_nums[card]["temps"]:
 | 
								for (i, name) in cls.stat_nums[card]["temps"]:
 | 
				
			||||||
				stat[f"temp{i}"] = (temp(i), name)
 | 
									stat[f"temp{i}"] = (temp(i), name)
 | 
				
			||||||
		elif cls.gpu_brand == "NVIDIA":
 | 
							elif cls.gpu_brand == "NVIDIA":
 | 
				
			||||||
 | 
								try:
 | 
				
			||||||
				temp = nvml.nvmlDeviceGetTemperature(card, nvml.NVML_TEMPERATURE_GPU)
 | 
									temp = nvml.nvmlDeviceGetTemperature(card, nvml.NVML_TEMPERATURE_GPU)
 | 
				
			||||||
				stat[f"temp1"] = temp
 | 
									stat[f"temp1"] = temp
 | 
				
			||||||
 | 
								except:
 | 
				
			||||||
 | 
									return NotImplemented
 | 
				
			||||||
		else:
 | 
							else:
 | 
				
			||||||
			errlog.debug("GPU not supported")
 | 
								errlog.debug("GPU not supported")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4282,7 +4284,10 @@ class GpuCollector(Collector):
 | 
				
			||||||
			volt = lambda n: cls._read(cls._get_hwmon(card) + f"in{n}_input") # mV
 | 
								volt = lambda n: cls._read(cls._get_hwmon(card) + f"in{n}_input") # mV
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		elif cls.gpu_brand == "NVIDIA":
 | 
							elif cls.gpu_brand == "NVIDIA":
 | 
				
			||||||
 | 
								try:
 | 
				
			||||||
				power = str(round(int(nvml.nvmlDeviceGetPowerUsage(cls.handle) / 1000)))
 | 
									power = str(round(int(nvml.nvmlDeviceGetPowerUsage(cls.handle) / 1000)))
 | 
				
			||||||
 | 
								except:
 | 
				
			||||||
 | 
									return NotImplemented
 | 
				
			||||||
		else:
 | 
							else:
 | 
				
			||||||
			errlog.debug("GPU not supported")
 | 
								errlog.debug("GPU not supported")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4297,7 +4302,7 @@ class GpuCollector(Collector):
 | 
				
			||||||
			volt = lambda n: int(cls._read(cls._get_hwmon(card) + f"in{n}_input")) # mV
 | 
								volt = lambda n: int(cls._read(cls._get_hwmon(card) + f"in{n}_input")) # mV
 | 
				
			||||||
		elif cls.gpu_brand == "NVIDIA":
 | 
							elif cls.gpu_brand == "NVIDIA":
 | 
				
			||||||
			# nvidia only allow voltage data to be fetched for their S-class products, see nvmlReturn_t nvmlUnitGetPsuInfo()
 | 
								# nvidia only allow voltage data to be fetched for their S-class products, see nvmlReturn_t nvmlUnitGetPsuInfo()
 | 
				
			||||||
			return ""
 | 
								return NotImplemented
 | 
				
			||||||
		else:
 | 
							else:
 | 
				
			||||||
			errlog.debug("GPU not supported")
 | 
								errlog.debug("GPU not supported")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4317,8 +4322,11 @@ class GpuCollector(Collector):
 | 
				
			||||||
			for (i, name) in cls.stat_nums[card]["freqs"]:
 | 
								for (i, name) in cls.stat_nums[card]["freqs"]:
 | 
				
			||||||
				stat[f"freq{i}"] = (freq(i), name)
 | 
									stat[f"freq{i}"] = (freq(i), name)
 | 
				
			||||||
		elif cls.gpu_brand == "NVIDIA":
 | 
							elif cls.gpu_brand == "NVIDIA":
 | 
				
			||||||
 | 
								try:
 | 
				
			||||||
				stat["freq0"] = (nvml.nvmlDeviceGetClockInfo(card, nvml.NVML_CLOCK_GRAPHICS), "GPU")
 | 
									stat["freq0"] = (nvml.nvmlDeviceGetClockInfo(card, nvml.NVML_CLOCK_GRAPHICS), "GPU")
 | 
				
			||||||
				stat["freq1"] = (nvml.nvmlDeviceGetClockInfo(card, nvml.NVML_CLOCK_MEM), "MEM")
 | 
									stat["freq1"] = (nvml.nvmlDeviceGetClockInfo(card, nvml.NVML_CLOCK_MEM), "MEM")
 | 
				
			||||||
 | 
								except:
 | 
				
			||||||
 | 
									return NotImplemented
 | 
				
			||||||
		else:
 | 
							else:
 | 
				
			||||||
			errlog.debug("GPU not supported")
 | 
								errlog.debug("GPU not supported")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4334,8 +4342,11 @@ class GpuCollector(Collector):
 | 
				
			||||||
			for (i, f_max) in cls.stat_nums[card]["fans"]:
 | 
								for (i, f_max) in cls.stat_nums[card]["fans"]:
 | 
				
			||||||
				stat[f"fan{i}"] = (fan(i), f_max)
 | 
									stat[f"fan{i}"] = (fan(i), f_max)
 | 
				
			||||||
		elif cls.gpu_brand == "NVIDIA":
 | 
							elif cls.gpu_brand == "NVIDIA":
 | 
				
			||||||
 | 
								try:
 | 
				
			||||||
				fan = nvml.nvmlDeviceGetFanSpeed(card)
 | 
									fan = nvml.nvmlDeviceGetFanSpeed(card)
 | 
				
			||||||
				stat[f"fans"] = fan
 | 
									stat[f"fans"] = fan
 | 
				
			||||||
 | 
								except:
 | 
				
			||||||
 | 
									return NotImplemented
 | 
				
			||||||
		else:
 | 
							else:
 | 
				
			||||||
			errlog.debug("GPU not supported")
 | 
								errlog.debug("GPU not supported")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4350,9 +4361,12 @@ class GpuCollector(Collector):
 | 
				
			||||||
				"gpu": int(cls._read(cls._get_device(card) + "gpu_busy_percent")),
 | 
									"gpu": int(cls._read(cls._get_device(card) + "gpu_busy_percent")),
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		elif cls.gpu_brand == "NVIDIA":
 | 
							elif cls.gpu_brand == "NVIDIA":
 | 
				
			||||||
 | 
								try:
 | 
				
			||||||
				gpu_stats = nvml.nvmlDeviceGetUtilizationRates(card)
 | 
									gpu_stats = nvml.nvmlDeviceGetUtilizationRates(card)
 | 
				
			||||||
				stat["gpu"] = int(gpu_stats.gpu)
 | 
									stat["gpu"] = int(gpu_stats.gpu)
 | 
				
			||||||
				stat["mem"] = int(gpu_stats.memory)
 | 
									stat["mem"] = int(gpu_stats.memory)
 | 
				
			||||||
 | 
								except:
 | 
				
			||||||
 | 
									return NotImplemented
 | 
				
			||||||
		else:
 | 
							else:
 | 
				
			||||||
			errlog.debug("GPU not supported")
 | 
								errlog.debug("GPU not supported")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue