diff --git a/glances/plugins/glances_cpu.py b/glances/plugins/glances_cpu.py index c9ce5501..fa115332 100644 --- a/glances/plugins/glances_cpu.py +++ b/glances/plugins/glances_cpu.py @@ -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'))) diff --git a/glances/plugins/glances_plugin.py b/glances/plugins/glances_plugin.py index d6107626..4603a89f 100644 --- a/glances/plugins/glances_plugin.py +++ b/glances/plugins/glances_plugin.py @@ -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,