Skip to content

Commit

Permalink
Remove tree view
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolargo committed Jan 27, 2018
1 parent 9356b70 commit 6317229
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 151 deletions.
3 changes: 0 additions & 3 deletions glances/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,6 @@ def init_args(self):
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,
Expand Down
2 changes: 1 addition & 1 deletion glances/outputs/glances_curses.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ def display(self, stats, cs_status=None):
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
Expand Down
3 changes: 0 additions & 3 deletions glances/plugins/glances_processcount.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,6 @@ def msg_curse(self, args=None, max_width=None):
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
124 changes: 14 additions & 110 deletions glances/plugins/glances_processlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,7 @@ def update(self):
# 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
Expand All @@ -121,87 +118,6 @@ def update(self):

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)
Expand Down Expand Up @@ -355,16 +271,10 @@ def get_process_curses_data(self, p, first, args):
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))
Expand Down Expand Up @@ -462,24 +372,19 @@ def msg_curse(self, args=None, max_width=None):
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
Expand Down Expand Up @@ -666,7 +571,6 @@ def __mmm_key(self, key, indice):
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):
Expand Down
35 changes: 8 additions & 27 deletions glances/processes.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ def __init__(self, cache_timeout=60):
# 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'
Expand Down Expand Up @@ -194,14 +190,6 @@ def disable_kernel_threads(self):
"""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."""
Expand Down Expand Up @@ -379,10 +367,6 @@ def getlist(self, sortedby=None):
"""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."""
Expand All @@ -396,14 +380,14 @@ def sort_key(self, key):

# 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:
Expand All @@ -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

Expand Down
7 changes: 0 additions & 7 deletions glances/standalone.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,6 @@ def __init__(self, config=None, args=None):
# 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()

Expand Down

3 comments on commit 6317229

@half-potato
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why tho

@nkoroste
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why was this removed? the only reason I installed this instead of htop

@luckydonald
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I miss this.

Please sign in to comment.