From 19005178194678833947612aaaf79580231493d5 Mon Sep 17 00:00:00 2001 From: Louis Boval Date: Wed, 12 Mar 2014 23:35:47 -0700 Subject: [PATCH] =?UTF-8?q?[pidcat]=20Allow=20package=20to=20specify=20a?= =?UTF-8?q?=20process=20as=20well=20=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: Android apps can use multiple processes (eg, chrome), which are identified as : in logs. The names are defined in the manifest. The main process is referred to as simply by android. Add the ability to specify a target process as part of what was until now the package name in pidcat, or all processes if no process is specified. Usage: * pidcat will match all of an app's processes (catchall). * pidcat : will match a given named process. ** In particular, pidcat : will ensure only the app's main/default process is matched. Test Plan: Run the script, try out with no process, empty (aka default) process, named process. Try multiple entries. --- pidcat.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pidcat.py b/pidcat.py index e514445..970e041 100755 --- a/pidcat.py +++ b/pidcat.py @@ -44,6 +44,13 @@ parser.add_argument('-e', '--emulator', dest='use_emulator', action='store_true' args = parser.parse_args() min_level = LOG_LEVELS_MAP[args.min_level] +# Store the names of packages for which to match all processes. +catchall_package = filter(lambda package: package.find(":") == -1, args.package) +# Store the name of processes to match exactly. +named_processes = filter(lambda package: package.find(":") != -1, args.package) +# Convert default process names from : (cli notation) to (android notation) in the exact names match group. +named_processes = map(lambda package: package if package.find(":") != len(package) - 1 else package[:-1], named_processes) + header_size = args.tag_width + 1 + 3 + 1 # space, level, space width = -1 @@ -157,8 +164,10 @@ app_pid = None def match_packages(token): if len(args.package) == 0: return True + if token in named_processes: + return True index = token.find(':') - return (token in args.package) if index == -1 else (token[:index] in args.package) + return (token in catchall_package) if index == -1 else (token[:index] in catchall_package) def parse_death(tag, message): if tag != 'ActivityManager':