提交 1ba459e6 编写于 作者: D desbma 提交者: Alessio Sergi

Sort lists in place when possible

上级 a6b2f7f6
......@@ -704,21 +704,16 @@ class GlancesProcesses(object):
# Sum of io_r + io_w
try:
# Sort process by IO rate (sum IO read + IO write)
listsorted = sorted(self.processlist,
key=lambda process: process[sortedby][0] -
process[sortedby][2] + process[sortedby][1] -
process[sortedby][3],
reverse=sortedreverse)
self.processlist.sort(key=lambda process: process[sortedby][0] -
process[sortedby][2] + process[sortedby][1] -
process[sortedby][3],
reverse=sortedreverse)
except Exception:
listsorted = sorted(self.processlist,
key=lambda process: process['cpu_percent'],
reverse=sortedreverse)
self.processlist.sort(key=lambda process: process['cpu_percent'],
reverse=sortedreverse)
else:
# Others sorts
listsorted = sorted(self.processlist,
key=lambda process: process[sortedby],
reverse=sortedreverse)
self.processlist = listsorted
self.processlist.sort(key=lambda process: process[sortedby],
reverse=sortedreverse)
return self.processlist
......@@ -140,8 +140,8 @@ class GlancesHistory(object):
# Find if anothers key ends with the key
# Ex: key='tx' => 'ethernet_tx'
# Add one curve per chart
stats_history_filtered = sorted(
[key for key in h.keys() if key.endswith('_' + i['name'])])
stats_history_filtered = [key for key in h.keys() if key.endswith('_' + i['name'])]
stats_history_filtered.sort()
logger.debug("Generate graphs: %s %s" %
(p, stats_history_filtered))
if len(stats_history_filtered) > 0:
......
......@@ -427,30 +427,23 @@ class Plugin(GlancesPlugin):
# Sum of io_r + io_w
try:
# Sort process by IO rate (sum IO read + IO write)
listsorted = sorted(self.stats,
key=lambda process: process[sortedby][0] -
process[sortedby][2] + process[sortedby][1] -
process[sortedby][3],
reverse=sortedreverse)
self.stats.sort(key=lambda process: process[sortedby][0] -
process[sortedby][2] + process[sortedby][1] -
process[sortedby][3],
reverse=sortedreverse)
except Exception:
listsorted = sorted(self.stats,
key=lambda process: process['cpu_percent'],
reverse=sortedreverse)
self.stats.sort(key=lambda process: process['cpu_percent'],
reverse=sortedreverse)
else:
# Others sorts
if tree:
self.stats.set_sorting(sortedby, sortedreverse)
else:
try:
listsorted = sorted(self.stats,
key=lambda process: process[sortedby],
reverse=sortedreverse)
self.stats.sort(key=lambda process: process[sortedby],
reverse=sortedreverse)
except (KeyError, TypeError):
listsorted = sorted(self.stats,
key=lambda process: process['name'],
reverse=False)
if not tree:
self.stats = listsorted
self.stats.sort(key=lambda process: process['name'],
reverse=False)
return self.stats
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册