Optimize CPU CTX display on the curse interface

This commit is contained in:
nicolargo 2017-05-07 15:39:03 +02:00
parent 2baf0d1de4
commit b91241c47f
2 changed files with 11 additions and 4 deletions

View File

@ -256,7 +256,8 @@ class Plugin(GlancesPlugin):
if 'ctx_switches' in self.stats:
msg = ' {:8}'.format('ctx_sw:')
ret.append(self.curse_add_line(msg, optional=self.get_views(key='ctx_switches', option='optional')))
msg = '{:>5}'.format(int(self.stats['ctx_switches'] // self.stats['time_since_update']))
msg = '{:>5}'.format(self.auto_unit(int(self.stats['ctx_switches'] // self.stats['time_since_update']),
min_symbol='M'))
ret.append(self.curse_add_line(
msg, self.get_views(key='ctx_switches', option='decoration'),
optional=self.get_views(key='ctx_switches', option='optional')))

View File

@ -805,7 +805,10 @@ class GlancesPlugin(object):
"""
self._align = value
def auto_unit(self, number, low_precision=False):
def auto_unit(self, number,
low_precision=False,
min_symbol='K'
):
"""Make a nice human-readable string out of number.
Number of decimal places increases as quantity approaches 1.
@ -819,10 +822,13 @@ class GlancesPlugin(object):
CASE: 1073741824 RESULT: 1024M low_precision: 1024M
CASE: 1181116006 RESULT: 1.10G low_precision: 1.1G
'low_precision=True' returns less decimal places potentially
sacrificing precision for more readability.
:low_precision: returns less decimal places potentially (default is False)
sacrificing precision for more readability.
:min_symbol: Do not approache if number < min_symbol (default is K)
"""
symbols = ('K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y')
if min_symbol in symbols:
symbols = symbols[symbols.index(min_symbol):]
prefix = {
'Y': 1208925819614629174706176,
'Z': 1180591620717411303424,