mirror of
				https://github.com/ARM-software/devlib.git
				synced 2025-11-04 07:51:21 +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:
		
				
					committed by
					
						
						Marc Bonnici
					
				
			
			
				
	
			
			
			
						parent
						
							8695344969
						
					
				
				
					commit
					117686996b
				
			@@ -1163,16 +1163,20 @@ class LinuxTarget(Target):
 | 
				
			|||||||
        else:
 | 
					        else:
 | 
				
			||||||
            return []
 | 
					            return []
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def ps(self, **kwargs):
 | 
					    def ps(self, threads=False, **kwargs):
 | 
				
			||||||
        command = 'ps -eo user,pid,ppid,vsize,rss,wchan,pcpu,state,fname'
 | 
					        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'))
 | 
					        lines = iter(convert_new_lines(self.execute(command)).split('\n'))
 | 
				
			||||||
        next(lines)  # header
 | 
					        next(lines)  # header
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        result = []
 | 
					        result = []
 | 
				
			||||||
        for line in lines:
 | 
					        for line in lines:
 | 
				
			||||||
            parts = re.split(r'\s+', line, maxsplit=8)
 | 
					            parts = re.split(r'\s+', line, maxsplit=9)
 | 
				
			||||||
            if parts and parts != ['']:
 | 
					            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:
 | 
					        if not kwargs:
 | 
				
			||||||
            return result
 | 
					            return result
 | 
				
			||||||
@@ -1419,18 +1423,32 @@ class AndroidTarget(Target):
 | 
				
			|||||||
                result.append(entry.pid)
 | 
					                result.append(entry.pid)
 | 
				
			||||||
        return result
 | 
					        return result
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def ps(self, **kwargs):
 | 
					    def ps(self, threads=False, **kwargs):
 | 
				
			||||||
        lines = iter(convert_new_lines(self.execute('ps')).split('\n'))
 | 
					        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
 | 
					        next(lines)  # header
 | 
				
			||||||
        result = []
 | 
					        result = []
 | 
				
			||||||
        for line in lines:
 | 
					        for line in lines:
 | 
				
			||||||
            parts = line.split(None, 8)
 | 
					            parts = line.split(None, maxsplit)
 | 
				
			||||||
            if not parts:
 | 
					            if not parts:
 | 
				
			||||||
                continue
 | 
					                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.
 | 
					                # wchan was blank; insert an empty field where it should be.
 | 
				
			||||||
                parts.insert(5, '')
 | 
					                parts.insert(6, '')
 | 
				
			||||||
            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:
 | 
					        if not kwargs:
 | 
				
			||||||
            return result
 | 
					            return result
 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
@@ -1854,7 +1872,7 @@ class AndroidTarget(Target):
 | 
				
			|||||||
        self.write_value(self._charging_enabled_path, int(bool(enabled)))
 | 
					        self.write_value(self._charging_enabled_path, int(bool(enabled)))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
FstabEntry = namedtuple('FstabEntry', ['device', 'mount_point', 'fs_type', 'options', 'dump_freq', 'pass_num'])
 | 
					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'])
 | 
					LsmodEntry = namedtuple('LsmodEntry', ['name', 'size', 'use_count', 'used_by'])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user