提交 ef915784 编写于 作者: N nicolargo

Merge branch 'enhance-process-curse' into develop

......@@ -43,6 +43,13 @@ class Plugin(GlancesPlugin):
stats is a list
"""
sort_for_human = {'io_counters': 'disk IO',
'cpu_percent': 'CPU consumption',
'memory_percent': 'memory consumption',
'cpu_times': 'process time',
'name': 'process name',
None: 'None'}
def __init__(self, args=None):
"""Init the plugin."""
super(Plugin, self).__init__(args=args,
......@@ -128,14 +135,17 @@ class Plugin(GlancesPlugin):
ret.append(self.curse_add_line(msg))
# Display sort information
try:
sort_human = self.sort_for_human[glances_processes.sort_key]
except KeyError:
sort_human = '?'
if glances_processes.auto_sort:
msg = 'sorted automatically'
ret.append(self.curse_add_line(msg))
msg = ' by {}'.format(glances_processes.sort_key)
ret.append(self.curse_add_line(msg))
msg = ' by {}'.format(sort_human)
else:
msg = 'sorted by {}'.format(glances_processes.sort_key)
ret.append(self.curse_add_line(msg))
msg = 'sorted by {}'.format(sort_human)
ret.append(self.curse_add_line(msg))
# Return the message with decoration
return ret
......@@ -44,14 +44,6 @@ def convert_timedelta(delta):
def split_cmdline(cmdline):
"""Return path, cmd and arguments for a process cmdline."""
# There is an issue in psutil for Electron/Atom processes (maybe others...)
# Tracked by https://github.com/nicolargo/glances/issues/1192
# https://github.com/giampaolo/psutil/issues/1179
# Add this dirty workarround (to be removed when the psutil is solved)
if len(cmdline) == 1:
cmdline = shlex.split(cmdline[0])
# /End of the direty workarround
path, cmd = os.path.split(cmdline[0])
arguments = ' '.join(cmdline[1:])
return path, cmd, arguments
......
......@@ -379,9 +379,12 @@ def sort_stats(stats, sortedby=None, reverse=True):
Reverse the sort if reverse is True.
"""
sortedby_secondary = 'cpu_percent'
if sortedby is None:
# No need to sort...
return stats
elif sortedby is 'cpu_percent':
sortedby_secondary = 'memory_percent'
if sortedby == 'io_counters':
# Specific case for io_counters
......@@ -393,12 +396,14 @@ def sort_stats(stats, sortedby=None, reverse=True):
process[sortedby][3],
reverse=reverse)
except Exception:
stats.sort(key=lambda x: weighted(x['cpu_percent']),
stats.sort(key=lambda x:(weighted(x['cpu_percent']),
weighted(x['memory_percent'])),
reverse=reverse)
else:
# Others sorts
try:
stats.sort(key=lambda x: weighted(x[sortedby]),
stats.sort(key=lambda x: (weighted(x[sortedby]),
weighted(x[sortedby_secondary])),
reverse=reverse)
except (KeyError, TypeError):
stats.sort(key=operator.itemgetter('name'),
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册