From 97b9c288135c2f3079fda54c75c8b321529a3fd6 Mon Sep 17 00:00:00 2001 From: Louis Boval Date: Wed, 12 Mar 2014 23:27:39 -0700 Subject: [PATCH] [pidcat] Display package:process_name in process birth/death messages Summary: Making sense of a birth/death message is made easier by specifying which process it applies to, and not just the component or the pid. Test Plan: Run, monitor message lines when cycling a multi-process app, inject None as a process name to check resilience. --- pidcat.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/pidcat.py b/pidcat.py index e514445..798b0a2 100755 --- a/pidcat.py +++ b/pidcat.py @@ -162,23 +162,26 @@ def match_packages(token): def parse_death(tag, message): if tag != 'ActivityManager': - return None + return None, None kill = PID_KILL.match(message) if kill: pid = kill.group(1) - if match_packages(kill.group(2)) and pid in pids: - return pid + package_line = kill.group(2) + if match_packages(package_line) and pid in pids: + return pid, package_line leave = PID_LEAVE.match(message) if leave: pid = leave.group(2) - if match_packages(leave.group(1)) and pid in pids: - return pid + package_line = leave.group(1) + if match_packages(package_line) and pid in pids: + return pid, package_line death = PID_DEATH.match(message) if death: pid = death.group(2) - if match_packages(death.group(1)) and pid in pids: - return pid - return None + package_line = death.group(1) + if match_packages(package_line) and pid in pids: + return pid, package_line + return None, None while adb.poll() is None: try: @@ -209,19 +212,19 @@ while adb.poll() is None: linebuf = '\n' linebuf += colorize(' ' * (header_size - 1), bg=WHITE) - linebuf += indent_wrap(' Process created for %s\n' % target) + linebuf += indent_wrap(' Process %s created for %s\n' % (line_package, target)) linebuf += colorize(' ' * (header_size - 1), bg=WHITE) linebuf += ' PID: %s UID: %s GIDs: %s' % (line_pid, line_uid, line_gids) linebuf += '\n' print(linebuf) last_tag = None # Ensure next log gets a tag printed - dead_pid = parse_death(tag, message) + dead_pid, dead_pname = parse_death(tag, message) if dead_pid: pids.remove(dead_pid) linebuf = '\n' linebuf += colorize(' ' * (header_size - 1), bg=RED) - linebuf += ' Process %s ended' % dead_pid + linebuf += ' Process %s (PID: %s) ended' % (dead_pname, dead_pid) linebuf += '\n' print(linebuf) last_tag = None # Ensure next log gets a tag printed