mirror of https://github.com/nicolargo/glances.git
Catch error on ADM GPU plugin and Python 3.9
This commit is contained in:
parent
e74dcc0060
commit
f587b281c0
|
|
@ -15,6 +15,7 @@ Currently supported:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from glances.globals import to_fahrenheit
|
from glances.globals import to_fahrenheit
|
||||||
|
from glances.logger import logger
|
||||||
from glances.plugins.gpu.cards.amd import AmdGPU
|
from glances.plugins.gpu.cards.amd import AmdGPU
|
||||||
from glances.plugins.gpu.cards.nvidia import NvidiaGPU
|
from glances.plugins.gpu.cards.nvidia import NvidiaGPU
|
||||||
from glances.plugins.plugin.model import GlancesPluginModel
|
from glances.plugins.plugin.model import GlancesPluginModel
|
||||||
|
|
@ -73,11 +74,21 @@ class GpuPlugin(GlancesPluginModel):
|
||||||
stats_init_value=[],
|
stats_init_value=[],
|
||||||
fields_description=fields_description,
|
fields_description=fields_description,
|
||||||
)
|
)
|
||||||
# Init the GPU API
|
# Init the Nvidia GPU API
|
||||||
self.nvidia = NvidiaGPU()
|
try:
|
||||||
self.amd = AmdGPU()
|
self.nvidia = NvidiaGPU()
|
||||||
|
except Exception as e:
|
||||||
|
logger.debug(f'Nvidia GPU initialization error: {e}')
|
||||||
|
self.nvidia = None
|
||||||
|
|
||||||
|
# Init the AMD GPU API
|
||||||
# Just for test purpose (uncomment to test on computer without AMD GPU)
|
# Just for test purpose (uncomment to test on computer without AMD GPU)
|
||||||
# self.amd = AmdGPU(drm_root_folder='./tests-data/plugins/gpu/amd/sys/class/drm')
|
# self.amd = AmdGPU(drm_root_folder='./tests-data/plugins/gpu/amd/sys/class/drm')
|
||||||
|
try:
|
||||||
|
self.amd = AmdGPU()
|
||||||
|
except Exception as e:
|
||||||
|
logger.debug(f'AMD GPU initialization error: {e}')
|
||||||
|
self.amd = None
|
||||||
|
|
||||||
# We want to display the stat in the curse interface
|
# We want to display the stat in the curse interface
|
||||||
self.display_curse = True
|
self.display_curse = True
|
||||||
|
|
@ -102,11 +113,13 @@ class GpuPlugin(GlancesPluginModel):
|
||||||
stats = self.get_init_value()
|
stats = self.get_init_value()
|
||||||
|
|
||||||
# Get the stats
|
# Get the stats
|
||||||
stats.extend(self.nvidia.get_device_stats())
|
if self.nvidia:
|
||||||
stats.extend(self.amd.get_device_stats())
|
stats.extend(self.nvidia.get_device_stats())
|
||||||
|
if self.amd:
|
||||||
|
stats.extend(self.amd.get_device_stats())
|
||||||
|
|
||||||
# !!!
|
# !!!
|
||||||
# Uncomment to test on computer without GPU
|
# Uncomment to test on computer without Nvidia GPU
|
||||||
# One GPU sample:
|
# One GPU sample:
|
||||||
# stats = [
|
# stats = [
|
||||||
# {
|
# {
|
||||||
|
|
|
||||||
|
|
@ -365,11 +365,7 @@ class TestGlances(unittest.TestCase):
|
||||||
def test_014_gpu(self):
|
def test_014_gpu(self):
|
||||||
"""Check GPU plugin."""
|
"""Check GPU plugin."""
|
||||||
print('INFO: [TEST_014] Check GPU stats')
|
print('INFO: [TEST_014] Check GPU stats')
|
||||||
gpu_plugin = stats.get_plugin('gpu')
|
stats_grab = stats.get_plugin('gpu').get_raw()
|
||||||
if not gpu_plugin:
|
|
||||||
print('INFO: GPU plugin is disabled, skipping test')
|
|
||||||
return
|
|
||||||
stats_grab = gpu_plugin.get_raw()
|
|
||||||
self.assertTrue(isinstance(stats_grab, list), msg='GPU stats is not a list')
|
self.assertTrue(isinstance(stats_grab, list), msg='GPU stats is not a list')
|
||||||
print(f'INFO: GPU stats: {stats_grab}')
|
print(f'INFO: GPU stats: {stats_grab}')
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue