Also filter on command line

This commit is contained in:
Nicolargo 2014-08-16 14:28:46 +02:00
parent 8302690995
commit bb2d9d4cae
2 changed files with 20 additions and 17 deletions

View File

@ -125,6 +125,7 @@ class GlancesProcesses(object):
# No filter => Not filtered
return False
else:
# logger.debug(self.get_process_filter() + " <> " + value + " => " + str(self.get_process_filter_re().match(value) is None))
return self.get_process_filter_re().match(value) is None
def __get_process_stats(self, proc,
@ -133,10 +134,10 @@ class GlancesProcesses(object):
extended_stats=False):
"""
Get process stats of the proc processes (proc is returned psutil.process_iter())
mandatory_stats: need for the sorting step
=> cpu_percent, memory_percent, io_counters, name
mandatory_stats: need for the sorting/filter step
=> cpu_percent, memory_percent, io_counters, name, cmdline
standard_stats: for all the displayed processes
=> username, cmdline, status, memory_info, cpu_times
=> username, status, memory_info, cpu_times
extended_stats: only for top processes (see issue #403)
=> connections (UDP/TCP), memory_swap...
"""
@ -150,6 +151,17 @@ class GlancesProcesses(object):
# Process CPU, MEM percent and name
procstat.update(proc.as_dict(attrs=['cpu_percent', 'memory_percent', 'name'], ad_value=''))
# Process command line (cached with internal cache)
try:
self.cmdline_cache[procstat['pid']]
except KeyError:
# Patch for issue #391
try:
self.cmdline_cache[procstat['pid']] = ' '.join(proc.cmdline())
except (AttributeError, psutil.AccessDenied, UnicodeDecodeError):
self.cmdline_cache[procstat['pid']] = ""
procstat['cmdline'] = self.cmdline_cache[procstat['pid']]
# Process IO
# procstat['io_counters'] is a list:
# [read_bytes, write_bytes, read_bytes_old, write_bytes_old, io_tag]
@ -196,17 +208,6 @@ class GlancesProcesses(object):
self.username_cache[procstat['pid']] = "?"
procstat['username'] = self.username_cache[procstat['pid']]
# Process command line (cached with internal cache)
try:
self.cmdline_cache[procstat['pid']]
except KeyError:
# Patch for issue #391
try:
self.cmdline_cache[procstat['pid']] = ' '.join(proc.cmdline())
except (AttributeError, psutil.AccessDenied, UnicodeDecodeError):
self.cmdline_cache[procstat['pid']] = ""
procstat['cmdline'] = self.cmdline_cache[procstat['pid']]
# Process status, nice, memory_info and cpu_times
procstat.update(proc.as_dict(attrs=['status', 'nice', 'memory_info', 'cpu_times']))
procstat['status'] = str(procstat['status'])[:1].upper()
@ -281,8 +282,10 @@ class GlancesProcesses(object):
s = self.__get_process_stats(proc,
mandatory_stats=True,
standard_stats=self.get_max_processes() is None)
if self.is_filtered(s['name']):
# Continue to the next process if it has to be filtered
if self.is_filtered(s['cmdline']) and self.is_filtered(s['name']):
continue
# Ok add the process to the list
processdict[proc] = s
# ignore the 'idle' process on Windows and *BSD
# ignore the 'kernel_task' process on OS X

View File

@ -481,7 +481,7 @@ class GlancesCurses(object):
# Display edit filter popup
if self.edit_filter:
new_filter = self.display_popup(_("Filter: "),
new_filter = self.display_popup(_("Process filter pattern: "),
is_input=True,
input_value=glances_processes.get_process_filter())
glances_processes.set_process_filter(new_filter)
@ -493,7 +493,7 @@ class GlancesCurses(object):
size_x=None, size_y=None,
duration=3,
is_input=False,
input_size=20,
input_size=30,
input_value=None):
"""
If is_input is False: