Correct an issue in last commit for #1875

This commit is contained in:
Nicolas Hennion 2021-06-11 17:07:29 +02:00
parent 7e8243baf8
commit 0e9e5e9512
3 changed files with 16 additions and 8 deletions

View File

@ -29,7 +29,7 @@ import sys
# Global name # Global name
# Version should start and end with a numerical char # Version should start and end with a numerical char
# See https://packaging.python.org/specifications/core-metadata/#version # See https://packaging.python.org/specifications/core-metadata/#version
__version__ = '3.2.0b1' __version__ = '3.2.0b2'
__author__ = 'Nicolas Hennion <nicolas@nicolargo.com>' __author__ = 'Nicolas Hennion <nicolas@nicolargo.com>'
__license__ = 'LGPLv3' __license__ = 'LGPLv3'

View File

@ -68,8 +68,12 @@ class CpuPercent(object):
cpu_freq = psutil.cpu_freq() cpu_freq = psutil.cpu_freq()
if hasattr(cpu_freq, 'current'): if hasattr(cpu_freq, 'current'):
self.cpu_info['cpu_hz_current'] = cpu_freq.current self.cpu_info['cpu_hz_current'] = cpu_freq.current
if hasattr(cpu_freq, 'cpu_hz'): else:
self.cpu_info['cpu_hz_current'] = None
if hasattr(cpu_freq, 'max'):
self.cpu_info['cpu_hz'] = cpu_freq.max self.cpu_info['cpu_hz'] = cpu_freq.max
else:
self.cpu_info['cpu_hz'] = None
# Reset timer for cache # Reset timer for cache
self.timer_cpu_info.reset(duration=self.cached_timer_cpu_info) self.timer_cpu_info.reset(duration=self.cached_timer_cpu_info)
return self.cpu_info return self.cpu_info

View File

@ -80,9 +80,10 @@ class Plugin(GlancesPlugin):
stats['swap'] = None stats['swap'] = None
# Get additional information # Get additional information
stats['cpu_name'] = cpu_percent.get_info()['cpu_name'] cpu_info = cpu_percent.get_info()
stats['cpu_hz_current'] = self._mhz_to_hz(cpu_percent.get_info()['cpu_hz_current']) stats['cpu_name'] = cpu_info['cpu_name']
stats['cpu_hz'] = self._mhz_to_hz(cpu_percent.get_info()['cpu_hz']) stats['cpu_hz_current'] = self._mhz_to_hz(cpu_info['cpu_hz_current']) if cpu_info['cpu_hz_current'] is not None else None
stats['cpu_hz'] = self._mhz_to_hz(cpu_info['cpu_hz']) if cpu_info['cpu_hz'] is not None else None
elif self.input_method == 'snmp': elif self.input_method == 'snmp':
# Not available # Not available
@ -126,9 +127,12 @@ class Plugin(GlancesPlugin):
# Build the string message # Build the string message
if 'cpu_name' in self.stats and 'cpu_hz_current' in self.stats and 'cpu_hz' in self.stats: if 'cpu_name' in self.stats and 'cpu_hz_current' in self.stats and 'cpu_hz' in self.stats:
msg_name = '{} - '.format(self.stats['cpu_name']) msg_name = self.stats['cpu_name']
msg_freq = '{:.2f}/{:.2f}GHz'.format(self._hz_to_ghz(self.stats['cpu_hz_current']), if self.stats['cpu_hz_current'] and self.stats['cpu_hz']:
self._hz_to_ghz(self.stats['cpu_hz'])) msg_freq = ' - {:.2f}/{:.2f}GHz'.format(self._hz_to_ghz(self.stats['cpu_hz_current']),
self._hz_to_ghz(self.stats['cpu_hz']))
else:
msg_freq = ''
if len(msg_name + msg_freq) - 6 <= max_width: if len(msg_name + msg_freq) - 6 <= max_width:
ret.append(self.curse_add_line(msg_name)) ret.append(self.curse_add_line(msg_name))
ret.append(self.curse_add_line(msg_freq)) ret.append(self.curse_add_line(msg_freq))