Remove tree view

This commit is contained in:
nicolargo 2018-01-27 14:01:27 +01:00
parent 9356b70c04
commit 631722992e
6 changed files with 23 additions and 151 deletions

View File

@ -213,9 +213,6 @@ Examples of use:
if not WINDOWS:
parser.add_argument('--hide-kernel-threads', action='store_true', default=False,
dest='no_kernel_threads', help='hide kernel threads in process list (not available on Windows)')
# if LINUX:
# parser.add_argument('--tree', action='store_true', default=False,
# dest='process_tree', help='display processes as a tree (Linux only)')
parser.add_argument('-b', '--byte', action='store_true', default=False,
dest='byte', help='display network rate in byte per second')
parser.add_argument('--diskio-show-ramfs', action='store_true', default=False,

View File

@ -533,7 +533,7 @@ class _GlancesCurses(object):
self.get_stats_display_height(__stat_display["docker"])))
try:
if self.args.enable_process_extended and not self.args.process_tree:
if self.args.enable_process_extended:
max_processes_displayed -= 4
except AttributeError:
pass

View File

@ -124,9 +124,6 @@ class Plugin(GlancesPlugin):
else:
msg = 'sorted by {}'.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

View File

@ -106,10 +106,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 glances_processes.is_tree_enabled():
self.stats = glances_processes.gettree()
else:
self.stats = glances_processes.getlist()
self.stats = glances_processes.getlist()
# Get the max values (dict)
# Use Deep copy to avoid change between update and display
@ -121,87 +118,6 @@ class Plugin(GlancesPlugin):
return self.stats
def get_process_tree_curses_data(self, node, args, first_level=True, max_node_count=None):
"""Get curses data to display for a process tree."""
ret = []
node_count = 0
if not node.is_root and ((max_node_count is None) or (max_node_count > 0)):
node_data = self.get_process_curses_data(node.stats, False, args)
node_count += 1
ret.extend(node_data)
for child in node.iter_children():
# stop if we have enough nodes to display
if max_node_count is not None and node_count >= max_node_count:
break
if max_node_count is None:
children_max_node_count = None
else:
children_max_node_count = max_node_count - node_count
child_data = self.get_process_tree_curses_data(child,
args,
first_level=node.is_root,
max_node_count=children_max_node_count)
if max_node_count is None:
node_count += len(child)
else:
node_count += min(children_max_node_count, len(child))
if not node.is_root:
child_data = self.add_tree_decoration(child_data, child is node.children[-1], first_level)
ret.extend(child_data)
return ret
def add_tree_decoration(self, child_data, is_last_child, first_level):
"""Add tree curses decoration and indentation to a subtree."""
# find process command indices in messages
pos = []
for i, m in enumerate(child_data):
if m.get("_tree_decoration", False):
del m["_tree_decoration"]
pos.append(i)
# add new curses items for tree decoration
new_child_data = []
new_pos = []
for i, m in enumerate(child_data):
if i in pos:
new_pos.append(len(new_child_data))
new_child_data.append(self.curse_add_line(""))
new_child_data[-1]["_tree_decoration"] = True
new_child_data.append(m)
child_data = new_child_data
pos = new_pos
if pos:
# draw node prefix
if is_last_child:
prefix = "└─"
else:
prefix = "├─"
child_data[pos[0]]["msg"] = prefix
# add indentation
for i in pos:
spacing = 2
if first_level:
spacing = 1
elif is_last_child and (i is not pos[0]):
# compensate indentation for missing '│' char
spacing = 3
child_data[i]["msg"] = "%s%s" % (" " * spacing, child_data[i]["msg"])
if not is_last_child:
# add '│' tree decoration
for i in pos[1:]:
old_str = child_data[i]["msg"]
if first_level:
child_data[i]["msg"] = "" + old_str[2:]
else:
child_data[i]["msg"] = old_str[:2] + "" + old_str[3:]
return child_data
def get_nice_alert(self, value):
"""Return the alert relative to the Nice configuration list"""
value = str(value)
@ -355,16 +271,10 @@ class Plugin(GlancesPlugin):
if os.path.isdir(path) and not args.process_short_name:
msg = ' {}'.format(path) + os.sep
ret.append(self.curse_add_line(msg, splittable=True))
if glances_processes.is_tree_enabled():
# mark position to add tree decoration
ret[-1]["_tree_decoration"] = True
ret.append(self.curse_add_line(cmd, decoration='PROCESS', splittable=True))
else:
msg = ' {}'.format(cmd)
ret.append(self.curse_add_line(msg, decoration='PROCESS', splittable=True))
if glances_processes.is_tree_enabled():
# mark position to add tree decoration
ret[-1]["_tree_decoration"] = True
if arguments:
msg = ' {}'.format(arguments)
ret.append(self.curse_add_line(msg, splittable=True))
@ -462,24 +372,19 @@ class Plugin(GlancesPlugin):
self.__msg_curse_header(ret, process_sort_key, args)
# Process list
if glances_processes.is_tree_enabled():
ret.extend(self.get_process_tree_curses_data(
self.__sort_stats(process_sort_key), args, first_level=True,
max_node_count=glances_processes.max_processes))
else:
# Loop over processes (sorted by the sort key previously compute)
first = True
for p in self.__sort_stats(process_sort_key):
ret.extend(self.get_process_curses_data(p, first, args))
# End of extended stats
first = False
if glances_processes.process_filter is not None:
if args.reset_minmax_tag:
args.reset_minmax_tag = not args.reset_minmax_tag
self.__mmm_reset()
self.__msg_curse_sum(ret, args=args)
self.__msg_curse_sum(ret, mmm='min', args=args)
self.__msg_curse_sum(ret, mmm='max', args=args)
# Loop over processes (sorted by the sort key previously compute)
first = True
for p in self.__sort_stats(process_sort_key):
ret.extend(self.get_process_curses_data(p, first, args))
# End of extended stats
first = False
if glances_processes.process_filter is not None:
if args.reset_minmax_tag:
args.reset_minmax_tag = not args.reset_minmax_tag
self.__mmm_reset()
self.__msg_curse_sum(ret, args=args)
self.__msg_curse_sum(ret, mmm='min', args=args)
self.__msg_curse_sum(ret, mmm='max', args=args)
# Return the message with decoration
return ret
@ -666,7 +571,6 @@ class Plugin(GlancesPlugin):
def __sort_stats(self, sortedby=None):
"""Return the stats (dict) sorted by (sortedby)."""
return sort_stats(self.stats, sortedby,
tree=glances_processes.is_tree_enabled(),
reverse=glances_processes.sort_reverse)
def __max_pid_size(self):

View File

@ -49,10 +49,6 @@ class GlancesProcesses(object):
# value = [ read_bytes_old, write_bytes_old ]
self.io_old = {}
# Wether or not to enable process tree
self._enable_tree = False
self.process_tree = None
# Init stats
self.auto_sort = True
self._sort_key = 'cpu_percent'
@ -194,14 +190,6 @@ 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
@property
def sort_reverse(self):
"""Return True to sort processes in reverse 'key' order, False instead."""
@ -379,10 +367,6 @@ class GlancesProcesses(object):
"""Get the processlist."""
return self.processlist
def gettree(self):
"""Get the process tree."""
return self.process_tree
@property
def sort_key(self):
"""Get the current sort key."""
@ -396,14 +380,14 @@ class GlancesProcesses(object):
# TODO: move this global function (also used in glances_processlist
# and logs) inside the GlancesProcesses class
def sort_stats(stats, sortedby=None, tree=False, reverse=True):
def sort_stats(stats, sortedby=None, reverse=True):
"""Return the stats (dict) sorted by (sortedby)
Reverse the sort if reverse is True."""
if sortedby is None:
# No need to sort...
return stats
if sortedby == 'io_counters' and not tree:
if sortedby == 'io_counters':
# Specific case for io_counters
# Sum of io_r + io_w
try:
@ -417,15 +401,12 @@ def sort_stats(stats, sortedby=None, tree=False, reverse=True):
reverse=reverse)
else:
# Others sorts
if tree:
stats.set_sorting(sortedby, reverse)
else:
try:
stats.sort(key=operator.itemgetter(sortedby),
reverse=reverse)
except (KeyError, TypeError):
stats.sort(key=operator.itemgetter('name'),
reverse=False)
try:
stats.sort(key=operator.itemgetter(sortedby),
reverse=reverse)
except (KeyError, TypeError):
stats.sort(key=operator.itemgetter('name'),
reverse=False)
return stats

View File

@ -64,13 +64,6 @@ class GlancesStandalone(object):
# Ignore kernel threads in process list
glances_processes.disable_kernel_threads()
# try:
# if args.process_tree:
# # Enable process tree view
# glances_processes.enable_tree()
# except AttributeError:
# pass
# Initial system informations update
self.stats.update()