From 4aa2cf2287e112d1c669146ac6b20ac247dc8238 Mon Sep 17 00:00:00 2001 From: Edison Wang Date: Wed, 12 Jun 2013 16:20:38 -0400 Subject: [PATCH 1/5] support multiple processes for the same package. --- pidcat.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/pidcat.py b/pidcat.py index 71ab7d9..f1aaf50 100755 --- a/pidcat.py +++ b/pidcat.py @@ -103,7 +103,7 @@ TAGTYPES = { 'E': colorize(' E ', fg=BLACK, bg=RED), } -PID_START = re.compile(r'^Start proc ([a-zA-Z0-9._]+) for ([a-z]+ [^:]+): pid=(\d+) uid=(\d+) gids=(.*)\r?$') +PID_START = re.compile(r'^Start proc ([a-zA-Z0-9._:]+) for ([a-z]+ [^:]+): pid=(\d+) uid=(\d+) gids=(.*)\r?$') PID_KILL = re.compile(r'^Killing (\d+):([a-zA-Z0-9._]+)/[^:]+: (.*)\r?$') PID_LEAVE = re.compile(r'^No longer want ([a-zA-Z0-9._]+) \(pid (\d+)\): .*\r?$') PID_DEATH = re.compile(r'^Process ([a-zA-Z0-9._]+) \(pid (\d+)\) has died.?\r$') @@ -120,17 +120,17 @@ def parse_death(tag, message): kill = PID_KILL.match(message) if kill: pid = kill.group(1) - if kill.group(2) == args.package and pid in pids: + if kill.group(2).find(args.package) != -1 and pid in pids: return pid leave = PID_LEAVE.match(message) if leave: pid = leave.group(2) - if leave.group(1) == args.package and pid in pids: + if leave.group(1).find(args.package) != -1 and pid in pids: return pid death = PID_DEATH.match(message) if death: pid = death.group(2) - if death.group(1) == args.package and pid in pids: + if death.group(1).find(args.package) != -1 and pid in pids: return pid return None @@ -154,7 +154,7 @@ while True: if start is not None: line_package, target, line_pid, line_uid, line_gids = start.groups() - if line_package == args.package: + if line_package.find(args.package) != -1: pids.add(line_pid) linebuf = colorize(' ' * (header_size - 1), bg=WHITE) @@ -164,6 +164,8 @@ while True: linebuf += '\n' print linebuf last_tag = None # Ensure next log gets a tag printed + else: + print line_package dead_pid = parse_death(tag, message) if dead_pid: From 7daa41e12c91936aa21b18480c13466657b6e2d0 Mon Sep 17 00:00:00 2001 From: Edison Wang Date: Wed, 12 Jun 2013 16:23:10 -0400 Subject: [PATCH 2/5] do not need to print this here. --- pidcat.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/pidcat.py b/pidcat.py index f1aaf50..d186420 100755 --- a/pidcat.py +++ b/pidcat.py @@ -164,8 +164,6 @@ while True: linebuf += '\n' print linebuf last_tag = None # Ensure next log gets a tag printed - else: - print line_package dead_pid = parse_death(tag, message) if dead_pid: From 3b8b9df4b80957937fbb3d3154d870126104907e Mon Sep 17 00:00:00 2001 From: Edison Wang Date: Wed, 12 Jun 2013 18:52:34 -0400 Subject: [PATCH 3/5] Check the package OR the package with the process token. --- pidcat.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/pidcat.py b/pidcat.py index d186420..29b3736 100755 --- a/pidcat.py +++ b/pidcat.py @@ -35,6 +35,8 @@ parser.add_argument('--tag-width', metavar='N', dest='tag_width', type=int, defa args = parser.parse_args() +package_process = args.package + ':' + header_size = args.tag_width + 1 + 3 + 1 # space, level, space # unpack the current terminal width/height @@ -114,23 +116,26 @@ input = os.popen('adb logcat') pids = set() last_tag = None +def belongs_package(token): + return (token == args.package or (token.find(package_process) != -1)); + def parse_death(tag, message): if tag != 'ActivityManager': return None kill = PID_KILL.match(message) if kill: pid = kill.group(1) - if kill.group(2).find(args.package) != -1 and pid in pids: + if belongs_package(kill.group(2)) and pid in pids: return pid leave = PID_LEAVE.match(message) if leave: pid = leave.group(2) - if leave.group(1).find(args.package) != -1 and pid in pids: + if belongs_package(leave.group(1)) and pid in pids: return pid death = PID_DEATH.match(message) if death: pid = death.group(2) - if death.group(1).find(args.package) != -1 and pid in pids: + if belongs_package(death.group(1)) and pid in pids: return pid return None @@ -154,7 +159,7 @@ while True: if start is not None: line_package, target, line_pid, line_uid, line_gids = start.groups() - if line_package.find(args.package) != -1: + if belongs_package(line_package): pids.add(line_pid) linebuf = colorize(' ' * (header_size - 1), bg=WHITE) From f48b9a9dde583b617838901e968f0858ee2a63ae Mon Sep 17 00:00:00 2001 From: Edison Wang Date: Thu, 13 Jun 2013 14:46:36 -0400 Subject: [PATCH 4/5] do not print the arg at begining. --- pidcat.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/pidcat.py b/pidcat.py index 5f0fc64..5e2ba7e 100755 --- a/pidcat.py +++ b/pidcat.py @@ -126,8 +126,6 @@ input = os.popen('adb logcat') pids = set() last_tag = None -print args.package - def belongs_package(token): index = token.find(':') return (token in args.package) if index == -1 else (token[:index] in args.package) From 5f3aadf6beccb4d836c731ee8ab3e5c3567006ef Mon Sep 17 00:00:00 2001 From: Edison Wang Date: Thu, 13 Jun 2013 14:48:32 -0400 Subject: [PATCH 5/5] renamed the function to be more descriptive. --- pidcat.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pidcat.py b/pidcat.py index 5e2ba7e..36a2d06 100755 --- a/pidcat.py +++ b/pidcat.py @@ -126,7 +126,7 @@ input = os.popen('adb logcat') pids = set() last_tag = None -def belongs_package(token): +def match_pacakges(token): index = token.find(':') return (token in args.package) if index == -1 else (token[:index] in args.package) @@ -136,17 +136,17 @@ def parse_death(tag, message): kill = PID_KILL.match(message) if kill: pid = kill.group(1) - if belongs_package(kill.group(2)) and pid in pids: + if match_pacakges(kill.group(2)) and pid in pids: return pid leave = PID_LEAVE.match(message) if leave: pid = leave.group(2) - if belongs_package(leave.group(1)) and pid in pids: + if match_pacakges(leave.group(1)) and pid in pids: return pid death = PID_DEATH.match(message) if death: pid = death.group(2) - if belongs_package(death.group(1)) and pid in pids: + if match_pacakges(death.group(1)) and pid in pids: return pid return None @@ -170,7 +170,7 @@ while True: if start is not None: line_package, target, line_pid, line_uid, line_gids = start.groups() - if belongs_package(line_package): + if match_pacakges(line_package): pids.add(line_pid) linebuf = colorize(' ' * (header_size - 1), bg=WHITE)