mirror of https://github.com/nicolargo/glances
Refactor some loop in the processes function
parent
da3c5474a8
commit
e5e3cefa45
|
@ -680,7 +680,6 @@ class _GlancesCurses(object):
|
||||||
new_filter = self.display_popup(
|
new_filter = self.display_popup(
|
||||||
'Process filter pattern: \n\n'
|
'Process filter pattern: \n\n'
|
||||||
+ 'Examples:\n'
|
+ 'Examples:\n'
|
||||||
+ '- python\n'
|
|
||||||
+ '- .*python.*\n'
|
+ '- .*python.*\n'
|
||||||
+ '- /usr/lib.*\n'
|
+ '- /usr/lib.*\n'
|
||||||
+ '- name:.*nautilus.*\n'
|
+ '- name:.*nautilus.*\n'
|
||||||
|
|
|
@ -286,21 +286,19 @@ class GlancesProcesses(object):
|
||||||
is_cached = True
|
is_cached = True
|
||||||
|
|
||||||
# Build the processes stats list (it is why we need psutil>=5.3.0)
|
# Build the processes stats list (it is why we need psutil>=5.3.0)
|
||||||
# This is on of the main bottleneck of Glances (see flame graph)
|
# This is one of the main bottleneck of Glances (see flame graph)
|
||||||
self.processlist = [
|
# Filter processes
|
||||||
p.info
|
self.processlist = list(filter(lambda p: not (BSD and p.info['name'] == 'idle') and
|
||||||
for p in psutil.process_iter(attrs=sorted_attrs, ad_value=None)
|
not (WINDOWS and p.info['name'] == 'System Idle Process') and
|
||||||
# OS-related processes filter
|
not (MACOS and p.info['name'] == 'kernel_task') and
|
||||||
if not (BSD and p.info['name'] == 'idle')
|
not (self.no_kernel_threads and LINUX and p.info['gids'].real == 0),
|
||||||
and not (WINDOWS and p.info['name'] == 'System Idle Process')
|
psutil.process_iter(attrs=sorted_attrs, ad_value=None)))
|
||||||
and not (MACOS and p.info['name'] == 'kernel_task')
|
# Only get the info key
|
||||||
and
|
self.processlist = [p.info for p in self.processlist]
|
||||||
# Kernel threads filter
|
|
||||||
not (self.no_kernel_threads and LINUX and p.info['gids'].real == 0)
|
|
||||||
]
|
|
||||||
|
|
||||||
# Sort the processes list by the current sort_key
|
# Sort the processes list by the current sort_key
|
||||||
self.processlist = sort_stats(self.processlist, sorted_by=self.sort_key, reverse=True)
|
self.processlist = sort_stats(self.processlist,
|
||||||
|
sorted_by=self.sort_key,
|
||||||
|
reverse=True)
|
||||||
|
|
||||||
# Update the processcount
|
# Update the processcount
|
||||||
self.update_processcount(self.processlist)
|
self.update_processcount(self.processlist)
|
||||||
|
@ -410,8 +408,9 @@ class GlancesProcesses(object):
|
||||||
# Save values to cache
|
# Save values to cache
|
||||||
self.processlist_cache[proc['pid']] = {cached: proc[cached] for cached in cached_attrs}
|
self.processlist_cache[proc['pid']] = {cached: proc[cached] for cached in cached_attrs}
|
||||||
|
|
||||||
# Apply filter
|
# Apply user filter
|
||||||
self.processlist = [p for p in self.processlist if not (self._filter.is_filtered(p))]
|
self.processlist = list(filter(lambda p: not self._filter.is_filtered(p),
|
||||||
|
self.processlist))
|
||||||
|
|
||||||
# Compute the maximum value for keys in self._max_values_list: CPU, MEM
|
# Compute the maximum value for keys in self._max_values_list: CPU, MEM
|
||||||
# Useful to highlight the processes with maximum values
|
# Useful to highlight the processes with maximum values
|
||||||
|
|
Loading…
Reference in New Issue