From 49c3c6c6be83ffa73e1a42f26fc2b65f51fe93c1 Mon Sep 17 00:00:00 2001 From: Nicolargo Date: Sun, 19 Jul 2015 03:59:05 +0200 Subject: [PATCH] IRIX mode off implementation (issue#628) --- docs/glances-doc.rst | 4 ++++ glances/core/glances_main.py | 2 ++ glances/outputs/glances_curses.py | 3 +++ glances/plugins/glances_help.py | 3 +++ glances/plugins/glances_processcount.py | 2 ++ glances/plugins/glances_processlist.py | 19 +++++++++++++++++-- man/glances.1 | 6 ++++++ 7 files changed, 37 insertions(+), 2 deletions(-) diff --git a/docs/glances-doc.rst b/docs/glances-doc.rst index 727f287c..81025b61 100644 --- a/docs/glances-doc.rst +++ b/docs/glances-doc.rst @@ -200,6 +200,7 @@ Command-Line Options -f PROCESS_FILTER, --process-filter PROCESS_FILTER set the process filter pattern (regular expression) --process-short-name force short name for processes name + --disable-irix Task's cpu usage will be divided by the total number of CPUs --hide-kernel-threads hide kernel threads in process list --tree display processes as a tree @@ -271,6 +272,8 @@ The following commands (key pressed) are supported while in Glances: Delete finished warning and critical log messages ``z`` Show/hide processes stats +``0`` + Task's cpu usage will be divided by the total number of CPUs ``1`` Switch between global CPU and per-CPU stats ``2`` @@ -604,6 +607,7 @@ The number of processes in the list is adapted to the screen size. ``CPU%`` % of CPU used by the process + If IRIX mode is off (aka Solaris mode), the value is divided by logical core number ``MEM%`` % of MEM used by the process ``VIRT`` diff --git a/glances/core/glances_main.py b/glances/core/glances_main.py index 433559ea..075c06f4 100644 --- a/glances/core/glances_main.py +++ b/glances/core/glances_main.py @@ -180,6 +180,8 @@ Start the client browser (browser mode):\n\ dest='process_filter', help='set the process filter pattern (regular expression)') parser.add_argument('--process-short-name', action='store_true', default=False, dest='process_short_name', help='force short name for processes name') + parser.add_argument('--disable-irix', action='store_true', default=False, + dest='disable_irix', help='Task\'s cpu usage will be divided by the total number of CPUs') if not is_windows: parser.add_argument('--hide-kernel-threads', action='store_true', default=False, dest='no_kernel_threads', help='hide kernel threads in process list') diff --git a/glances/outputs/glances_curses.py b/glances/outputs/glances_curses.py index 7e2a334c..ef5a9a9b 100644 --- a/glances/outputs/glances_curses.py +++ b/glances/outputs/glances_curses.py @@ -252,6 +252,9 @@ class _GlancesCurses(object): elif self.pressedkey == 10: # 'ENTER' > Edit the process filter self.edit_filter = not self.edit_filter + elif self.pressedkey == ord('0'): + # '0' > Switch between IRIX and Solaris mode + self.args.disable_irix = not self.args.disable_irix elif self.pressedkey == ord('1'): # '1' > Switch between CPU and PerCPU information self.args.percpu = not self.args.percpu diff --git a/glances/plugins/glances_help.py b/glances/plugins/glances_help.py index 333c3a89..48f8d40b 100644 --- a/glances/plugins/glances_help.py +++ b/glances/plugins/glances_help.py @@ -88,6 +88,7 @@ class Plugin(GlancesPlugin): self.view_data['quit'] = msg_col2.format('q', 'Quit (Esc and Ctrl-C also work)') self.view_data['enable_disable_top_extends_stats'] = msg_col.format('e', 'Enable/disable top extended stats') self.view_data['enable_disable_short_processname'] = msg_col.format('/', 'Enable/disable short processes name') + self.view_data['enable_disable_irix'] = msg_col.format('0', 'Enable/disable Irix process CPU') self.view_data['enable_disable_docker'] = msg_col2.format('D', 'Enable/disable Docker stats') self.view_data['enable_disable_quick_look'] = msg_col.format('3', 'Enable/disable quick look plugin') self.view_data['show_hide_ip'] = msg_col2.format('I', 'Show/hide IP module') @@ -162,6 +163,8 @@ class Plugin(GlancesPlugin): ret.append(self.curse_new_line()) ret.append(self.curse_add_line(self.view_data['enable_disable_short_processname'])) ret.append(self.curse_new_line()) + ret.append(self.curse_add_line(self.view_data['enable_disable_irix'])) + ret.append(self.curse_new_line()) ret.append(self.curse_new_line()) diff --git a/glances/plugins/glances_processcount.py b/glances/plugins/glances_processcount.py index 2841b791..eb69001b 100644 --- a/glances/plugins/glances_processcount.py +++ b/glances/plugins/glances_processcount.py @@ -126,6 +126,8 @@ class Plugin(GlancesPlugin): msg = 'sorted by {0}'.format(glances_processes.sort_key) ret.append(self.curse_add_line(msg)) ret[-1]["msg"] += ", %s view" % ("tree" if glances_processes.is_tree_enabled() else "flat") + # if args.disable_irix: + # ret[-1]["msg"] += " - IRIX off" # Return the message with decoration return ret diff --git a/glances/plugins/glances_processlist.py b/glances/plugins/glances_processlist.py index 422b1bd6..771461b3 100644 --- a/glances/plugins/glances_processlist.py +++ b/glances/plugins/glances_processlist.py @@ -25,6 +25,7 @@ import os from datetime import timedelta # Import Glances libs +from glances.plugins.glances_core import Plugin as CorePlugin from glances.core.glances_globals import is_windows from glances.core.glances_processes import glances_processes from glances.plugins.glances_plugin import GlancesPlugin @@ -61,6 +62,12 @@ class Plugin(GlancesPlugin): # Trying to display proc time self.tag_proc_time = True + # Call CorePlugin to get the core number (needed when not in IRIX mode / Solaris mode) + try: + self.nb_log_core = CorePlugin(args=self.args).update()["log"] + except Exception: + self.nb_log_core = 0 + # Note: 'glances_processes' is already init in the glances_processes.py script def get_key(self): @@ -174,7 +181,10 @@ class Plugin(GlancesPlugin): ret = [self.curse_new_line()] # CPU if 'cpu_percent' in p and p['cpu_percent'] is not None and p['cpu_percent'] != '': - msg = '{0:>6.1f}'.format(p['cpu_percent']) + if args.disable_irix and self.nb_log_core != 0: + msg = '{0:>6.1f}'.format(p['cpu_percent'] / float(self.nb_log_core)) + else: + msg = '{0:>6.1f}'.format(p['cpu_percent']) ret.append(self.curse_add_line(msg, self.get_alert(p['cpu_percent'], header="cpu"))) else: @@ -393,7 +403,12 @@ class Plugin(GlancesPlugin): sort_style = 'SORT' # Header - msg = '{0:>6}'.format('CPU%') + if args.disable_irix and 0 < self.nb_log_core < 10: + msg = '{0:>6}'.format('CPU%/' + str(self.nb_log_core)) + elif args.disable_irix and self.nb_log_core != 0: + msg = '{0:>6}'.format('CPU%/C') + else: + msg = '{0:>6}'.format('CPU%') ret.append(self.curse_add_line(msg, sort_style if process_sort_key == 'cpu_percent' else 'DEFAULT')) msg = '{0:>6}'.format('MEM%') ret.append(self.curse_add_line(msg, sort_style if process_sort_key == 'memory_percent' else 'DEFAULT')) diff --git a/man/glances.1 b/man/glances.1 index 18cb57f3..0a4463ca 100644 --- a/man/glances.1 +++ b/man/glances.1 @@ -145,6 +145,9 @@ set the process filter pattern (regular expression) .B \-\-process-short-name force short name for processes name .TP +.B \-\-disable-irix +Task's cpu usage will be divided by the total number of CPUs +.TP .B \-\-hide-kernel-threads hide kernel threads in process list .TP @@ -246,6 +249,9 @@ Show/hide processes stats .B z Show/hide processes list (for low CPU consumption) .TP +.B 0 +Task's cpu usage will be divided by the total number of CPUs +.TP .B 1 Switch between global CPU and per-CPU stats .TP