mirror of
https://github.com/nicolargo/glances.git
synced 2024-11-25 08:33:22 +03:00
commit
eee6dd6dbf
@ -42,6 +42,21 @@ def convert_timedelta(delta):
|
||||
return hours, minutes, seconds, microseconds
|
||||
|
||||
|
||||
def split_process_cmdline(process):
|
||||
"""Return dirname, basename, arguments for a process, with unknown parts set to None. """
|
||||
dirname = None
|
||||
basename = process['name']
|
||||
arguments = None
|
||||
if process['exe'] and process['cmdline'].startswith(process['exe']):
|
||||
dn, bn = os.path.split(process['exe'])
|
||||
dirname = dn or None
|
||||
basename = bn or process['name']
|
||||
arguments = process['cmdline'][len(process['exe']):].lstrip()
|
||||
elif process['cmdline'].startswith(process['name']):
|
||||
arguments = process['cmdline'][len(process['name']):].lstrip()
|
||||
return dirname, basename, arguments
|
||||
|
||||
|
||||
class Plugin(GlancesPlugin):
|
||||
|
||||
"""Glances' processes plugin.
|
||||
@ -287,31 +302,27 @@ class Plugin(GlancesPlugin):
|
||||
ret.append(self.curse_add_line(msg, optional=True, additional=True))
|
||||
|
||||
# Command line
|
||||
# If no command line for the process is available, fallback to
|
||||
# the bare process name instead
|
||||
cmdline = p['cmdline']
|
||||
argument = ' '.join(cmdline.split()[1:])
|
||||
dirname, name, arguments = split_process_cmdline(p)
|
||||
try:
|
||||
if cmdline == '':
|
||||
msg = ' {0}'.format(p['name'])
|
||||
if (dirname is None) and (arguments is None):
|
||||
msg = ' {0}'.format(name)
|
||||
ret.append(self.curse_add_line(msg, splittable=True))
|
||||
elif args.process_short_name:
|
||||
msg = ' {0}'.format(p['name'])
|
||||
msg = ' {0}'.format(name)
|
||||
ret.append(self.curse_add_line(msg, decoration='PROCESS', splittable=True))
|
||||
msg = ' {0}'.format(argument)
|
||||
msg = ' {0}'.format(arguments)
|
||||
ret.append(self.curse_add_line(msg, splittable=True))
|
||||
else:
|
||||
cmd = cmdline.split()[0]
|
||||
path, basename = os.path.split(cmd)
|
||||
if os.path.isdir(path):
|
||||
msg = ' {0}'.format(path) + os.sep
|
||||
if dirname is not None:
|
||||
msg = ' {0}'.format(dirname) + os.sep
|
||||
ret.append(self.curse_add_line(msg, splittable=True))
|
||||
ret.append(self.curse_add_line(basename, decoration='PROCESS', splittable=True))
|
||||
msg = name
|
||||
else:
|
||||
msg = ' {0}'.format(basename)
|
||||
ret.append(self.curse_add_line(msg, decoration='PROCESS', splittable=True))
|
||||
msg = ' {0}'.format(argument)
|
||||
ret.append(self.curse_add_line(msg, splittable=True))
|
||||
msg = ' {0}'.format(name)
|
||||
ret.append(self.curse_add_line(msg, decoration='PROCESS', splittable=True))
|
||||
if arguments is not None:
|
||||
msg = ' {0}'.format(arguments)
|
||||
ret.append(self.curse_add_line(msg, splittable=True))
|
||||
except UnicodeEncodeError:
|
||||
ret.append(self.curse_add_line('', splittable=True))
|
||||
|
||||
|
@ -377,7 +377,7 @@ class GlancesProcesses(object):
|
||||
try:
|
||||
procstat.update(proc.as_dict(
|
||||
attrs=['username', 'cpu_percent', 'memory_percent',
|
||||
'name', 'cpu_times'], ad_value=''))
|
||||
'name', 'exe', 'cpu_times'], ad_value=''))
|
||||
except psutil.NoSuchProcess:
|
||||
# Try/catch for issue #432
|
||||
return None
|
||||
|
Loading…
Reference in New Issue
Block a user