提交 6a667d63 编写于 作者: D desbma

Add command line --tree option and remove hardcoded boolean

上级 5c3a2698
......@@ -128,6 +128,8 @@ class GlancesMain(object):
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'))
parser.add_argument('--tree', action='store_true', default=False,
dest='process_tree', help=_('display processes as a tree'))
parser.add_argument('-b', '--byte', action='store_true', default=False,
dest='byte', help=_('display network rate in byte per second'))
parser.add_argument('-1', '--percpu', action='store_true', default=False,
......
......@@ -26,8 +26,6 @@ import collections
import psutil
import re
PROCESS_TREE = True # TODO remove that and take command line parameter
class ProcessTreeNode(object):
......@@ -220,8 +218,11 @@ class GlancesProcesses(object):
# value = [ read_bytes_old, write_bytes_old ]
self.io_old = {}
# Init stats
# Wether or not to enable process tree
self._enable_tree = False
self.process_tree = None
# Init stats
self.resetsort()
self.processlist = []
self.processcount = {
......@@ -310,6 +311,14 @@ class GlancesProcesses(object):
""" Ignore kernel threads in process list. """
self.no_kernel_threads = True
def enable_tree(self):
""" Enable process tree. """
self._enable_tree = True
def is_tree_enabled(self):
""" Return True if process tree is enabled, False instead. """
return self._enable_tree
def __get_process_stats(self, proc,
mandatory_stats=True,
standard_stats=True,
......@@ -558,7 +567,7 @@ class GlancesProcesses(object):
except:
pass
if PROCESS_TREE:
if self._enable_tree:
self.process_tree = ProcessTreeNode.buildTree(processdict,
self.getsortkey(),
self.no_kernel_threads)
......@@ -656,7 +665,7 @@ class GlancesProcesses(object):
def setmanualsortkey(self, sortedby):
"""Set the current sort key for manual sort."""
self.processmanualsort = sortedby
if PROCESS_TREE and (self.process_tree is not None):
if self._enable_tree and (self.process_tree is not None):
self.process_tree.setSorting(sortedby, sortedby != "name")
return self.processmanualsort
......
......@@ -49,10 +49,14 @@ class GlancesStandalone(object):
if args.process_filter is not None:
glances_processes.set_process_filter(args.process_filter)
# Ignore kernel threads in process list
if (not is_windows) and args.no_kernel_threads:
# Ignore kernel threads in process list
glances_processes.disable_kernel_threads()
if args.process_tree:
# Enable process tree view
glances_processes.enable_tree()
# Initial system informations update
self.stats.update()
......
......@@ -19,8 +19,6 @@
"""Curses interface class."""
PROCESS_TREE = True
# Import system lib
import sys
......@@ -425,7 +423,7 @@ class GlancesCurses(object):
# Adapt number of processes to the available space
max_processes_displayed = screen_y - 11 - \
self.get_stats_display_height(stats_alert)
if self.args.enable_process_extended and not PROCESS_TREE:
if self.args.enable_process_extended and not self.args.process_tree:
max_processes_displayed -= 4
if max_processes_displayed < 0:
max_processes_displayed = 0
......
......@@ -26,8 +26,6 @@ from glances.plugins.glances_plugin import GlancesPlugin
# Note: history items list is not compliant with process count
# if a filter is applyed, the graph will show the filtered processes count
PROCESS_TREE = True # TODO remove that and take command line parameter
class Plugin(GlancesPlugin):
......@@ -127,7 +125,7 @@ class Plugin(GlancesPlugin):
else:
msg = _("sorted by {0}").format(glances_processes.getmanualsortkey())
ret.append(self.curse_add_line(msg))
ret[-1]["msg"] += ", %s view" % ("tree" if PROCESS_TREE else "flat")
ret[-1]["msg"] += ", %s view" % ("tree" if glances_processes.is_tree_enabled() else "flat")
# Return the message with decoration
return ret
......@@ -27,8 +27,6 @@ from datetime import timedelta
from glances.core.glances_globals import glances_processes, is_linux, is_bsd, is_mac, is_windows, logger
from glances.plugins.glances_plugin import GlancesPlugin
PROCESS_TREE = True # TODO remove that and take command line parameter
class Plugin(GlancesPlugin):
......@@ -59,7 +57,7 @@ class Plugin(GlancesPlugin):
# Update stats using the standard system lib
# Note: Update is done in the processcount plugin
# Just return the processes list
if PROCESS_TREE:
if glances_processes.is_tree_enabled():
self.stats = glances_processes.gettree()
else:
self.stats = glances_processes.getlist()
......@@ -396,7 +394,7 @@ class Plugin(GlancesPlugin):
# Trying to display proc time
self.tag_proc_time = True
if PROCESS_TREE:
if glances_processes.is_tree_enabled():
ret.extend(self.get_process_tree_curses_data(self.sortstats(process_sort_key),
args,
first_level=True,
......@@ -422,7 +420,9 @@ class Plugin(GlancesPlugin):
if sortedby == 'name':
sortedreverse = False
if sortedby == 'io_counters' and not PROCESS_TREE:
tree = glances_processes.is_tree_enabled()
if sortedby == 'io_counters' and not tree:
# Specific case for io_counters
# Sum of io_r + io_w
try:
......@@ -438,7 +438,7 @@ class Plugin(GlancesPlugin):
reverse=sortedreverse)
else:
# Others sorts
if PROCESS_TREE:
if tree:
self.stats.setSorting(sortedby, sortedreverse)
else:
try:
......@@ -450,7 +450,7 @@ class Plugin(GlancesPlugin):
key=lambda process: process['name'],
reverse=False)
if not PROCESS_TREE:
if not tree:
self.stats = listsorted
return self.stats
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册