diff --git a/pidcat.py b/pidcat.py index 29b3736..5f0fc64 100755 --- a/pidcat.py +++ b/pidcat.py @@ -30,13 +30,12 @@ import termios import struct parser = argparse.ArgumentParser(description='Filter logcat by package name') -parser.add_argument('package', help='Application package name') +parser.add_argument('package', nargs='+', help='Application package name(s)') parser.add_argument('--tag-width', metavar='N', dest='tag_width', type=int, default=22, help='Width of log tag') +parser.add_argument('--color-gc', dest='color_gc', action='store_true', help='Color garbage collection') 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 @@ -45,17 +44,16 @@ HEIGHT, WIDTH = struct.unpack('hh',data) BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE = range(8) -def colorize(message, fg=None, bg=None): - ret = '' +RESET = '\033[0m' + +def termcolor(fg=None, bg=None): codes = [] if fg is not None: codes.append('3%d' % fg) if bg is not None: codes.append('10%d' % bg) - if codes: - ret += '\033[%sm' % ';'.join(codes) - ret += message - if codes: - ret += '\033[0m' - return ret + return '\033[%sm' % ';'.join(codes) if codes else '' + +def colorize(message, fg=None, bg=None): + return termcolor(fg, bg) + message + RESET def indent_wrap(message): wrap_area = WIDTH - header_size @@ -79,6 +77,7 @@ KNOWN_TAGS = { 'ActivityThread': WHITE, 'AndroidRuntime': CYAN, 'jdwp': WHITE, + 'StrictMode': WHITE, } def allocate_color(tag): @@ -94,9 +93,20 @@ def allocate_color(tag): RULES = { - #re.compile(r"([\w\.@]+)=([\w\.@]+)"): r"%s\1%s=%s\2%s" % (format(fg=BLUE), format(fg=GREEN), format(fg=BLUE), format(reset=True)), + # StrictMode policy violation; ~duration=319 ms: android.os.StrictMode$StrictModeDiskWriteViolation: policy=31 violation=1 + re.compile(r'^(StrictMode policy violation)(; ~duration=)(\d+ ms)') + : r'%s\1%s\2%s\3%s' % (termcolor(RED), RESET, termcolor(YELLOW), RESET), } +# Only enable GC coloring if the user opted-in +if args.color_gc: + # GC_CONCURRENT freed 3617K, 29% free 20525K/28648K, paused 4ms+5ms, total 85ms + key = re.compile(r'^(GC_(?:CONCURRENT|FOR_M?ALLOC|EXTERNAL_ALLOC|EXPLICIT) )(freed