summaryrefslogtreecommitdiff
path: root/src/gallium/tools
diff options
context:
space:
mode:
authorMatti Hamalainen <ccr@tnsp.org>2022-01-24 23:02:48 +0200
committerMatti Hämäläinen <ccr@tnsp.org>2022-06-28 11:40:58 +0000
commit8819d372e5df93389bd72d2281a9119e8d402366 (patch)
tree196232ebd783f95ad4d8bd1c01d3d9d179dab7c1 /src/gallium/tools
parent3421d9ecade49ac892776f366853c5d0600855f6 (diff)
pytracediff: add per-line difference highlighting for blocks
Highlight differing _lines_ in the differing blocks, with somewhat different ANSI colors. Signed-off-by: Matti Hamalainen <ccr@tnsp.org> Acked-by: Mike Blumenkrantz <michael.blumenkrantz@gmail.com> Reviewed-by: Dylan Baker <dylan@pnwbakers.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17135>
Diffstat (limited to 'src/gallium/tools')
-rwxr-xr-xsrc/gallium/tools/trace/pytracediff.py30
1 files changed, 24 insertions, 6 deletions
diff --git a/src/gallium/tools/trace/pytracediff.py b/src/gallium/tools/trace/pytracediff.py
index 64f2722302d..2e7888cf947 100755
--- a/src/gallium/tools/trace/pytracediff.py
+++ b/src/gallium/tools/trace/pytracediff.py
@@ -43,8 +43,10 @@ PKK_ANSI_ESC = '\33['
PKK_ANSI_NORMAL = '0m'
PKK_ANSI_RED = '31m'
PKK_ANSI_GREEN = '32m'
+PKK_ANSI_YELLOW = '33m'
PKK_ANSI_PURPLE = '35m'
PKK_ANSI_BOLD = '1m'
+PKK_ANSI_ITALIC = '3m'
###
@@ -234,9 +236,16 @@ def pkk_parse_trace(filename, options, state):
return parser.call_stack
-def pkk_get_line(data, nline, indent, width):
+def pkk_get_line(data, nline):
if nline < len(data):
- tmp = indent + data[nline]
+ return data[nline]
+ else:
+ return None
+
+
+def pkk_format_line(line, indent, width):
+ if line is not None:
+ tmp = indent + line
if len(tmp) > width:
return tmp[0:(width - 3)] + "..."
else:
@@ -343,8 +352,7 @@ if __name__ == "__main__":
ansi2 = ""
elif tag == "replace":
sep = ">"
- ansi1 = PKK_ANSI_ESC + PKK_ANSI_BOLD
- ansi2 = PKK_ANSI_ESC + PKK_ANSI_BOLD
+ ansi1 = ansi2 = PKK_ANSI_ESC + PKK_ANSI_BOLD
else:
pkk_fatal(f"Internal error, unsupported difflib.SequenceMatcher operation '{tag}'.")
@@ -394,11 +402,21 @@ if __name__ == "__main__":
else:
indent = ""
+ line1 = pkk_get_line(data1, nline)
+ line2 = pkk_get_line(data2, nline)
+
+ # Highlight differing lines if not plain
+ if not options.plain and line1 != line2:
+ if tag == "insert" or tag == "delete":
+ ansi1 = ansi1 + PKK_ANSI_ESC + PKK_ANSI_BOLD
+ elif tag == "replace":
+ ansi1 = ansi2 = ansi1 + PKK_ANSI_ESC + PKK_ANSI_YELLOW
+
# Output line
print(colfmt.format(
- ansi1, pkk_get_line(data1, nline, indent, colwidth), ansiend,
+ ansi1, pkk_format_line(line1, indent, colwidth), ansiend,
ansisep, sep, ansiend,
- ansi2, pkk_get_line(data2, nline, indent, colwidth), ansiend).
+ ansi2, pkk_format_line(line2, indent, colwidth), ansiend).
rstrip())
nline += 1