1
0
mirror of https://github.com/ARM-software/devlib.git synced 2025-01-31 02:00:45 +00:00

target: support threads in ps

Adds 'tid' attribute to PsEntry namedtuple. This is equal to the PID of
the process.

Adds 'threads=True' parameter to target.ps(). When true, PsEntrys will be
returned for all threads on the target, not just processes. The 'tid' will
be the distinct PID for each thread, rather than the owning process.
This commit is contained in:
Stephen Kyle 2020-07-10 10:12:25 +01:00 committed by Marc Bonnici
parent 8695344969
commit 117686996b

View File

@ -1163,16 +1163,20 @@ class LinuxTarget(Target):
else:
return []
def ps(self, **kwargs):
command = 'ps -eo user,pid,ppid,vsize,rss,wchan,pcpu,state,fname'
def ps(self, threads=False, **kwargs):
ps_flags = '-eo'
if threads:
ps_flags = '-eLo'
command = 'ps {} user,pid,tid,ppid,vsize,rss,wchan,pcpu,state,fname'.format(ps_flags)
lines = iter(convert_new_lines(self.execute(command)).split('\n'))
next(lines) # header
result = []
for line in lines:
parts = re.split(r'\s+', line, maxsplit=8)
parts = re.split(r'\s+', line, maxsplit=9)
if parts and parts != ['']:
result.append(PsEntry(*(parts[0:1] + list(map(int, parts[1:5])) + parts[5:])))
result.append(PsEntry(*(parts[0:1] + list(map(int, parts[1:6])) + parts[6:])))
if not kwargs:
return result
@ -1419,18 +1423,32 @@ class AndroidTarget(Target):
result.append(entry.pid)
return result
def ps(self, **kwargs):
lines = iter(convert_new_lines(self.execute('ps')).split('\n'))
def ps(self, threads=False, **kwargs):
maxsplit = 9 if threads else 8
command = 'ps'
if threads:
command = 'ps -AT'
lines = iter(convert_new_lines(self.execute(command)).split('\n'))
next(lines) # header
result = []
for line in lines:
parts = line.split(None, 8)
parts = line.split(None, maxsplit)
if not parts:
continue
if len(parts) == 8:
wchan_missing = False
if len(parts) == maxsplit:
wchan_missing = True
if not threads:
# Duplicate PID into TID location.
parts.insert(2, parts[1])
if wchan_missing:
# wchan was blank; insert an empty field where it should be.
parts.insert(5, '')
result.append(PsEntry(*(parts[0:1] + list(map(int, parts[1:5])) + parts[5:])))
parts.insert(6, '')
result.append(PsEntry(*(parts[0:1] + list(map(int, parts[1:6])) + parts[6:])))
if not kwargs:
return result
else:
@ -1854,7 +1872,7 @@ class AndroidTarget(Target):
self.write_value(self._charging_enabled_path, int(bool(enabled)))
FstabEntry = namedtuple('FstabEntry', ['device', 'mount_point', 'fs_type', 'options', 'dump_freq', 'pass_num'])
PsEntry = namedtuple('PsEntry', 'user pid ppid vsize rss wchan pc state name')
PsEntry = namedtuple('PsEntry', 'user pid tid ppid vsize rss wchan pc state name')
LsmodEntry = namedtuple('LsmodEntry', ['name', 'size', 'use_count', 'used_by'])