From 092ffc186925aeaf002e484a1b3f143edbf9bd60 Mon Sep 17 00:00:00 2001 From: Adam Hupp Date: Mon, 29 Sep 2014 21:12:51 -0700 Subject: [PATCH 1/2] Revert "Print line if we have not seen any pids created yet" This reverts commit cd01ccf7202c40969f509a9bea188c8d01bb95d9. --- pidcat.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pidcat.py b/pidcat.py index 8e83a8c..d4caf00 100755 --- a/pidcat.py +++ b/pidcat.py @@ -177,7 +177,6 @@ if sys.stdin.isatty(): else: adb = FakeStdinProcess() pids = set() -seen_pids = False last_tag = None app_pid = None @@ -236,7 +235,6 @@ while adb.poll() is None: if match_packages(line_package): pids.add(line_pid) - seen_pids = True app_pid = line_pid @@ -266,7 +264,7 @@ while adb.poll() is None: message = message.lstrip() owner = app_pid - if seen_pids and owner not in pids: + if owner not in pids: continue if level in LOG_LEVELS_MAP and LOG_LEVELS_MAP[level] < min_level: continue From 493e12a55c92c61a6daa444569ebac2830793891 Mon Sep 17 00:00:00 2001 From: Adam Hupp Date: Mon, 29 Sep 2014 21:39:55 -0700 Subject: [PATCH 2/2] Handle alternative log format for process start Some phones (like my samsung) do not log the 'Start proc ...' line in logcat to indicate process start. In my case it does log a line like E/dalvikvm(pid): >>>>>> com.my.package [ more stuff ] This commit adds support for that format to pidcat. --- pidcat.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/pidcat.py b/pidcat.py index d4caf00..a41d96c 100755 --- a/pidcat.py +++ b/pidcat.py @@ -139,7 +139,8 @@ TAGTYPES = { 'F': colorize(' F ', fg=BLACK, bg=RED), } -PID_START = re.compile(r'^Start proc ([a-zA-Z0-9._:]+) for ([a-z]+ [^:]+): pid=(\d+) uid=(\d+) gids=(.*)$') +PID_START = re.compile(r'^.*: Start proc ([a-zA-Z0-9._:]+) for ([a-z]+ [^:]+): pid=(\d+) uid=(\d+) gids=(.*)$') +PID_START_DALVIK = re.compile(r'^E/dalvikvm\((\d+)\): >>>>> ([a-zA-Z0-9._:]+) \[ userId:0 \| appId:(\d+) \]$') PID_KILL = re.compile(r'^Killing (\d+):([a-zA-Z0-9._:]+)/[^:]+: (.*)$') PID_LEAVE = re.compile(r'^No longer want ([a-zA-Z0-9._:]+) \(pid (\d+)\): .*$') PID_DEATH = re.compile(r'^Process ([a-zA-Z0-9._:]+) \(pid (\d+)\) has died.?$') @@ -211,6 +212,17 @@ def parse_death(tag, message): return pid, package_line return None, None +def parse_start_proc(line): + start = PID_START.match(line) + if start is not None: + line_package, target, line_pid, line_uid, line_gids = start.groups() + return line_package, target, line_pid, line_uid, line_gids + start = PID_START_DALVIK.match(line) + if start is not None: + line_pid, line_package, line_uid = start.groups() + return line_package, '', line_pid, line_uid, '' + return None + while adb.poll() is None: try: line = adb.stdout.readline().decode('utf-8', 'replace').strip() @@ -228,11 +240,9 @@ while adb.poll() is None: continue level, tag, owner, message = log_line.groups() - - start = PID_START.match(message) - if start is not None: - line_package, target, line_pid, line_uid, line_gids = start.groups() - + start = parse_start_proc(line) + if start: + line_package, target, line_pid, line_uid, line_gids = start if match_packages(line_package): pids.add(line_pid)