mirror of
https://github.com/nicolargo/glances.git
synced 2026-03-15 12:27:24 -04:00
Fix max process limit not working with tree view
This commit is contained in:
@@ -100,6 +100,17 @@ class ProcessTreeNode(object):
|
||||
|
||||
return total
|
||||
|
||||
def __len__(self):
|
||||
"""Return the number of nodes in the tree starting from this node."""
|
||||
total = 0
|
||||
nodes_to_sum = collections.deque([self])
|
||||
while nodes_to_sum:
|
||||
current_node = nodes_to_sum.pop()
|
||||
if not current_node.is_root:
|
||||
total += 1
|
||||
nodes_to_sum.extend(current_node.children)
|
||||
return total
|
||||
|
||||
def __iter__(self):
|
||||
""" Iterator returning ProcessTreeNode in sorted order. """
|
||||
if not self.is_root:
|
||||
@@ -529,8 +540,8 @@ class GlancesProcesses(object):
|
||||
|
||||
for i, node in enumerate(self.process_tree):
|
||||
# Only retreive stats for visible processes (get_max_processes)
|
||||
# if (self.get_max_processes() is not None) and (i >= self.get_max_processes()):
|
||||
# break
|
||||
if (self.get_max_processes() is not None) and (i >= self.get_max_processes()):
|
||||
break
|
||||
|
||||
# add standard stats
|
||||
new_stats = self.__get_process_stats(node.process,
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
|
||||
"""Curses interface class."""
|
||||
|
||||
PROCESS_TREE = True
|
||||
|
||||
# Import system lib
|
||||
import sys
|
||||
|
||||
@@ -423,7 +425,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:
|
||||
if self.args.enable_process_extended and not PROCESS_TREE:
|
||||
max_processes_displayed -= 4
|
||||
if max_processes_displayed < 0:
|
||||
max_processes_displayed = 0
|
||||
|
||||
@@ -70,12 +70,18 @@ class Plugin(GlancesPlugin):
|
||||
|
||||
return self.stats
|
||||
|
||||
def get_process_tree_curses_data(self, node, args, first_level=True):
|
||||
def get_process_tree_curses_data(self, node, args, first_level=True, max_node_count=None):
|
||||
ret = []
|
||||
if not node.is_root:
|
||||
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 i, child in enumerate(node.children):
|
||||
# stop if we have enough nodes to display
|
||||
if (max_node_count is not None) and (node_count >= max_node_count):
|
||||
break
|
||||
|
||||
has_other_children = False
|
||||
if ((len(node.children) == 1) or # only one child process
|
||||
(i == len(node.children) - 1)): # last child process
|
||||
@@ -83,7 +89,20 @@ class Plugin(GlancesPlugin):
|
||||
else:
|
||||
prefix = "├─"
|
||||
has_other_children = True
|
||||
child_data = self.get_process_tree_curses_data(child, args, node.is_root)
|
||||
|
||||
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:
|
||||
# TODO remove msg index hardcoding
|
||||
child_data[12]["msg"] = "%s%s" % (prefix, child_data[12]["msg"])
|
||||
@@ -365,7 +384,10 @@ class Plugin(GlancesPlugin):
|
||||
self.tag_proc_time = True
|
||||
|
||||
if PROCESS_TREE:
|
||||
ret.extend(self.get_process_tree_curses_data(self.sortlist(process_sort_key), args))
|
||||
ret.extend(self.get_process_tree_curses_data(self.sortlist(process_sort_key),
|
||||
args,
|
||||
first_level=True,
|
||||
max_node_count=glances_processes.get_max_processes()))
|
||||
else:
|
||||
# Loop over processes (sorted by the sort key previously compute)
|
||||
first = True
|
||||
|
||||
Reference in New Issue
Block a user