From ec7b0ac54f533a45f15e3763c67f8447117d355a Mon Sep 17 00:00:00 2001 From: Nicolargo Date: Thu, 14 Aug 2014 22:27:57 +0200 Subject: Add IO Nice level to top process --- glances/core/glances_processes.py | 7 ++-- glances/plugins/glances_processlist.py | 66 ++++++++++++++++++++++++++-------- 2 files changed, 56 insertions(+), 17 deletions(-) diff --git a/glances/core/glances_processes.py b/glances/core/glances_processes.py index 10f40134..27a43701 100644 --- a/glances/core/glances_processes.py +++ b/glances/core/glances_processes.py @@ -175,6 +175,8 @@ class GlancesProcesses(object): # Number of handles (Windows only) if is_windows: procstat.update(proc.as_dict(attrs=['num_handles'])) + else: + procstat['num_handles'] = None # SWAP memory (Only on Linux based OS) # http://www.cyberciti.biz/faq/linux-which-process-is-using-swap/ @@ -196,9 +198,8 @@ class GlancesProcesses(object): # http://pythonhosted.org/psutil/#psutil.Process.ionice if is_linux or is_windows: procstat.update(proc.as_dict(attrs=['ionice'])) - - # !!! Only for dev - logger.debug("EXTENDED STATS: %s" % procstat) + else: + procstat['ionice'] = None return procstat diff --git a/glances/plugins/glances_processlist.py b/glances/plugins/glances_processlist.py index 0a38291d..8cd4e2ef 100644 --- a/glances/plugins/glances_processlist.py +++ b/glances/plugins/glances_processlist.py @@ -239,24 +239,27 @@ class Plugin(GlancesPlugin): ret.append(self.curse_add_line("", splittable=True)) # Add extended stats but only for the top processes - # !!! CPU consumption !!!! + # !!! CPU consumption ??? + # TODO: extended stats into the web interface if first and 'extended_stats' in p: # Left padding xpad = ' ' * 13 # First line is CPU affinity - ret.append(self.curse_new_line()) - msg = xpad + _('CPU affinity: ') + ','.join(str(i) for i in p['cpu_affinity']) - ret.append(self.curse_add_line(msg)) + if p['cpu_affinity'] is not None: + ret.append(self.curse_new_line()) + msg = xpad + _('CPU affinity: ') + str(len(p['cpu_affinity'])) + _(' cores') + ret.append(self.curse_add_line(msg)) # Second line is memory info - ret.append(self.curse_new_line()) - msg = xpad + _('Memory info: ') - for k, v in p['memory_info_ex']._asdict().items(): - # Ignore rss and vms (already displayed) - if k not in ['rss', 'vms'] and v is not None: - msg += k + ' ' + self.auto_unit(v, low_precision=False) + ' ' - if p['memory_swap'] is not None: - msg += _('swap ') + self.auto_unit(p['memory_swap'], low_precision=False) - ret.append(self.curse_add_line(msg)) + if p['memory_info_ex'] is not None: + ret.append(self.curse_new_line()) + msg = xpad + _('Memory info: ') + for k, v in p['memory_info_ex']._asdict().items(): + # Ignore rss and vms (already displayed) + if k not in ['rss', 'vms'] and v is not None: + msg += k + ' ' + self.auto_unit(v, low_precision=False) + ' ' + if p['memory_swap'] is not None: + msg += _('swap ') + self.auto_unit(p['memory_swap'], low_precision=False) + ret.append(self.curse_add_line(msg)) # Third line is for openned files/network sessions ret.append(self.curse_new_line()) msg = xpad + _('Openned: ') @@ -264,11 +267,46 @@ class Plugin(GlancesPlugin): msg += _('threads ') + str(p['num_threads']) + ' ' if p['num_fds'] is not None: msg += _('files ') + str(p['num_fds']) + ' ' + if p['num_handles'] is not None: + msg += _('handles ') + str(p['num_handles']) + ' ' if p['tcp'] is not None: msg += _('TCP ') + str(p['tcp']) + ' ' - if p['tcp'] is not None: + if p['udp'] is not None: msg += _('UDP ') + str(p['udp']) + ' ' ret.append(self.curse_add_line(msg)) + # Fouth line is IO nice level (only Linux and Windows OS) + if p['ionice'] is not None: + ret.append(self.curse_new_line()) + msg = xpad + _('IO nice: ') + k = _('Class is ') + v = p['ionice'].ioclass + # Linux: The scheduling class. 0 for none, 1 for real time, 2 for best-effort, 3 for idle. + # Windows: On Windows only ioclass is used and it can be set to 2 (normal), 1 (low) or 0 (very low). + if is_windows: + if v == 0: + msg += k + 'Very Low' + elif v == 1: + msg += k + 'Low' + elif v == 2: + msg += _('No specific I/O priority') + else: + msg += k + str(v) + else: + if v == 0: + msg += _('No specific I/O priority') + elif v == 1: + msg += k + 'Real Time' + elif v == 2: + msg += k + 'Best Effort' + elif v == 3: + msg += k + 'IDLE' + else: + msg += k + str(v) + # value is a number which goes from 0 to 7. + # The higher the value, the lower the I/O priority of the process. + if hasattr(p['ionice'], 'value') and p['ionice'].value != 0: + msg += _(' (value %s/7)') % str(p['ionice'].value) + ret.append(self.curse_add_line(msg)) # End of extended stats first = False -- cgit v1.2.3