From 4ee7873d7fe908cc7ffd0e97a7172901c768aef0 Mon Sep 17 00:00:00 2001 From: luzeshu Date: Tue, 12 Mar 2019 10:57:02 +0800 Subject: [PATCH 1/4] log: add timestamp --- coloredlogcat.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/coloredlogcat.py b/coloredlogcat.py index 576a050..63b5e1c 100755 --- a/coloredlogcat.py +++ b/coloredlogcat.py @@ -35,12 +35,13 @@ ] # Width of various columns; set to -1 to hide +TIME_WIDTH = 18 USER_WIDTH = 3 PROCESS_WIDTH = 8 TAG_WIDTH = 20 PRIORITY_WIDTH = 3 -HEADER_SIZE = USER_WIDTH + PROCESS_WIDTH + TAG_WIDTH + PRIORITY_WIDTH + 4 +HEADER_SIZE = TIME_WIDTH + USER_WIDTH + PROCESS_WIDTH + TAG_WIDTH + PRIORITY_WIDTH + 4 # unpack the current terminal width/height data = fcntl.ioctl(sys.stdout.fileno(), termios.TIOCGWINSZ, '1234') @@ -111,6 +112,7 @@ def allocate_color(tag): "F": "%s%s%s " % (format(fg=BLACK, bg=RED), "F".center(PRIORITY_WIDTH), format(reset=True)), } +redetail = re.compile("^([0-9]+-[0-9]+ [0-9\:\.]+)\s+([0-9]+)\s+([0-9]+) ([A-Z]) ([^\:]+)\: (.*)$") retag = re.compile("^([A-Z])/([^\(]+)\(([^\)]+)\): (.*)$") retime = re.compile("(?:(\d+)s)?([\d.]+)\dms") reproc = re.compile(r"^I/ActivityManager.*?: Start proc .*?: pid=(\d+) uid=(\d+)") @@ -135,7 +137,7 @@ def millis_color(match): # if someone is piping in to us, use stdin as input. if not, invoke adb logcat if os.isatty(sys.stdin.fileno()): - input = os.popen("adb %s logcat -v brief" % adb_args) + input = os.popen("adb %s logcat" % adb_args) else: input = sys.stdin @@ -153,17 +155,21 @@ def millis_color(match): if match: KNOWN_PIDS[int(match.group(1))] = int(match.group(2)) - match = retag.match(line) + match = redetail.match(line) if not match: print line continue - priority, tag, process, message = match.groups() + time, ppid, process, priority, tag, message = match.groups() linebuf = StringIO.StringIO() tag = tag.strip() if tag in IGNORED: continue + # time + if TIME_WIDTH > 0: + linebuf.write(time) + # center user info if USER_WIDTH > 0: pid = int(process) From 7e3f41376661b7d83184b0c1952468f8ce99cfa7 Mon Sep 17 00:00:00 2001 From: luzeshu Date: Tue, 12 Mar 2019 23:01:46 +0800 Subject: [PATCH 2/4] log: add ppid --- coloredlogcat.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/coloredlogcat.py b/coloredlogcat.py index 63b5e1c..97ff3b7 100755 --- a/coloredlogcat.py +++ b/coloredlogcat.py @@ -36,12 +36,13 @@ # Width of various columns; set to -1 to hide TIME_WIDTH = 18 +PPID_WIDTH = 7 USER_WIDTH = 3 -PROCESS_WIDTH = 8 +PROCESS_WIDTH = 7 TAG_WIDTH = 20 PRIORITY_WIDTH = 3 -HEADER_SIZE = TIME_WIDTH + USER_WIDTH + PROCESS_WIDTH + TAG_WIDTH + PRIORITY_WIDTH + 4 +HEADER_SIZE = TIME_WIDTH + PPID_WIDTH + USER_WIDTH + PROCESS_WIDTH + TAG_WIDTH + PRIORITY_WIDTH + 6 # unpack the current terminal width/height data = fcntl.ioctl(sys.stdout.fileno(), termios.TIOCGWINSZ, '1234') @@ -168,7 +169,7 @@ def millis_color(match): # time if TIME_WIDTH > 0: - linebuf.write(time) + linebuf.write("%s%s%s " % (format(fg=GREEN, bg=BLACK, bright=False), time, format(reset=True))) # center user info if USER_WIDTH > 0: @@ -181,6 +182,11 @@ def millis_color(match): else: linebuf.write(" " * (USER_WIDTH + 1)) + # ppid + if PPID_WIDTH > 0: + ppid = ppid.strip().center(PPID_WIDTH) + linebuf.write("%s%s%s " % (format(fg=BLACK, bg=BLACK, bright=True), ppid, format(reset=True))) + # center process info if PROCESS_WIDTH > 0: process = process.strip().center(PROCESS_WIDTH) From a51edae9d27598d824b763156b30184f8ccd93f1 Mon Sep 17 00:00:00 2001 From: luzeshu Date: Tue, 31 Mar 2020 16:44:23 +0800 Subject: [PATCH 3/4] fix bugs: 1. jsharkey/android-tools#6 2. tag is overlapped when it was too long. --- coloredlogcat.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/coloredlogcat.py b/coloredlogcat.py index 97ff3b7..e931213 100755 --- a/coloredlogcat.py +++ b/coloredlogcat.py @@ -113,7 +113,7 @@ def allocate_color(tag): "F": "%s%s%s " % (format(fg=BLACK, bg=RED), "F".center(PRIORITY_WIDTH), format(reset=True)), } -redetail = re.compile("^([0-9]+-[0-9]+ [0-9\:\.]+)\s+([0-9]+)\s+([0-9]+) ([A-Z]) ([^\:]+)\: (.*)$") +redetail = re.compile("^([0-9]+-[0-9]+ [0-9\:\.]+)\s+([0-9]+)\s+([0-9]+) ([\sVDIWEF\s]) ([\S]*)\s*\: (.*)$") retag = re.compile("^([A-Z])/([^\(]+)\(([^\)]+)\): (.*)$") retime = re.compile("(?:(\d+)s)?([\d.]+)\dms") reproc = re.compile(r"^I/ActivityManager.*?: Start proc .*?: pid=(\d+) uid=(\d+)") @@ -143,6 +143,9 @@ def millis_color(match): input = sys.stdin while True: + line_header_size = HEADER_SIZE + line_tag_width = TAG_WIDTH + try: line = input.readline() except KeyboardInterrupt: @@ -162,6 +165,9 @@ def millis_color(match): continue time, ppid, process, priority, tag, message = match.groups() + if (len(tag) > line_tag_width): + line_tag_width = len(tag) + line_header_size = TIME_WIDTH + PPID_WIDTH + USER_WIDTH + PROCESS_WIDTH + line_tag_width + PRIORITY_WIDTH + 6 linebuf = StringIO.StringIO() tag = tag.strip() @@ -195,14 +201,14 @@ def millis_color(match): # right-align tag title and allocate color if needed tag = tag.strip() if "avc: denied" in message: - tag = tag[-TAG_WIDTH:].rjust(TAG_WIDTH) + tag = tag[-line_tag_width:].rjust(line_tag_width) linebuf.write("%s%s%s " % (format(fg=WHITE, bg=RED, dim=False), tag, format(reset=True))) elif tag in HIGHLIGHT: - tag = tag[-TAG_WIDTH:].rjust(TAG_WIDTH) + tag = tag[-line_tag_width:].rjust(line_tag_width) linebuf.write("%s%s%s " % (format(fg=BLACK, bg=WHITE, dim=False), tag, format(reset=True))) else: color = allocate_color(tag) - tag = tag[-TAG_WIDTH:].rjust(TAG_WIDTH) + tag = tag[-line_tag_width:].rjust(line_tag_width) linebuf.write("%s%s%s " % (format(fg=color, dim=False), tag, format(reset=True))) # write out tagtype colored edge @@ -216,7 +222,7 @@ def millis_color(match): message = retime.sub(millis_color, message) # insert line wrapping as needed - message = indent_wrap(message, HEADER_SIZE, WIDTH) + message = indent_wrap(message, line_header_size, WIDTH) linebuf.write(message) print linebuf.getvalue() From 6256d6e0b3c017776cc53f8cfb75f68d11e4d3fb Mon Sep 17 00:00:00 2001 From: luzeshu Date: Wed, 1 Apr 2020 11:46:06 +0800 Subject: [PATCH 4/4] Adjust format --- coloredlogcat.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/coloredlogcat.py b/coloredlogcat.py index e931213..4c12372 100755 --- a/coloredlogcat.py +++ b/coloredlogcat.py @@ -37,7 +37,7 @@ # Width of various columns; set to -1 to hide TIME_WIDTH = 18 PPID_WIDTH = 7 -USER_WIDTH = 3 +USER_WIDTH = 0 PROCESS_WIDTH = 7 TAG_WIDTH = 20 PRIORITY_WIDTH = 3 @@ -78,7 +78,7 @@ def indent_wrap(message, indent=0, width=80): return messagebuf.getvalue() USER_COLORS = [BLUE,YELLOW,RED,GREEN,MAGENTA,CYAN] -LAST_USED = [RED,GREEN,YELLOW,BLUE,MAGENTA,CYAN,WHITE] +LAST_USED = [RED,GREEN,YELLOW,MAGENTA,CYAN,WHITE] KNOWN_TAGS = { "dalvikvm": BLUE, "art": BLUE, @@ -105,7 +105,7 @@ def allocate_color(tag): return color PRIORITIES = { - "V": "%s%s%s " % (format(fg=WHITE, bg=BLACK), "V".center(PRIORITY_WIDTH), format(reset=True)), + "V": "%s%s%s " % (format(fg=BLACK, bg=WHITE), "V".center(PRIORITY_WIDTH), format(reset=True)), "D": "%s%s%s " % (format(fg=BLACK, bg=BLUE), "D".center(PRIORITY_WIDTH), format(reset=True)), "I": "%s%s%s " % (format(fg=BLACK, bg=GREEN), "I".center(PRIORITY_WIDTH), format(reset=True)), "W": "%s%s%s " % (format(fg=BLACK, bg=YELLOW), "W".center(PRIORITY_WIDTH), format(reset=True)), @@ -198,6 +198,13 @@ def millis_color(match): process = process.strip().center(PROCESS_WIDTH) linebuf.write("%s%s%s " % (format(fg=BLACK, bg=BLACK, bright=True), process, format(reset=True))) + # write out tagtype colored edge + if not priority in PRIORITIES: + print line + continue + + linebuf.write(PRIORITIES[priority]) + # right-align tag title and allocate color if needed tag = tag.strip() if "avc: denied" in message: @@ -211,13 +218,6 @@ def millis_color(match): tag = tag[-line_tag_width:].rjust(line_tag_width) linebuf.write("%s%s%s " % (format(fg=color, dim=False), tag, format(reset=True))) - # write out tagtype colored edge - if not priority in PRIORITIES: - print line - continue - - linebuf.write(PRIORITIES[priority]) - # color any high-millis operations message = retime.sub(millis_color, message)