pytracediff: make -M ("method only") option print arguments for differing calls

Basically implement the last item on the original feature request list of #4609.

Example: ./pytracediff.py good.xml bad.xml -NM

Or suppress common calls completely via -C, e.g. -NC etc.

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>
This commit is contained in:
Matti Hamalainen
2022-01-25 15:27:34 +02:00
committed by Matti Hämäläinen
parent 8819d372e5
commit cf4d1c1fed

View File

@@ -107,9 +107,10 @@ class PKKPrettyPrinter(PrettyPrinter):
def __init__(self, options): def __init__(self, options):
self.options = options self.options = options
def entry_start(self): def entry_start(self, show_args):
self.data = [] self.data = []
self.line = "" self.line = ""
self.show_args = show_args
def entry_get(self): def entry_get(self):
if self.line != "": if self.line != "":
@@ -189,7 +190,7 @@ class PKKPrettyPrinter(PrettyPrinter):
else: else:
self.function(node.method) self.function(node.method)
if not self.options.method_only: if not self.options.method_only or self.show_args:
self.text("(") self.text("(")
if len(node.args): if len(node.args):
self.newline() self.newline()
@@ -333,26 +334,32 @@ if __name__ == "__main__":
printer = PKKPrettyPrinter(options) printer = PKKPrettyPrinter(options)
prevtag = ""
for tag, start1, end1, start2, end2 in opcodes: for tag, start1, end1, start2, end2 in opcodes:
if tag == "equal": if tag == "equal":
show_args = False
if options.suppress_common: if options.suppress_common:
print("[...]") if tag != prevtag:
print("[...]")
continue continue
sep = "|" sep = "|"
ansi1 = ansi2 = ansiend = "" ansi1 = ansi2 = ansiend = ""
show_args = False
elif tag == "insert": elif tag == "insert":
sep = "+" sep = "+"
ansi1 = "" ansi1 = ""
ansi2 = PKK_ANSI_ESC + PKK_ANSI_GREEN ansi2 = PKK_ANSI_ESC + PKK_ANSI_GREEN
show_args = True
elif tag == "delete": elif tag == "delete":
sep = "-" sep = "-"
ansi1 = PKK_ANSI_ESC + PKK_ANSI_RED ansi1 = PKK_ANSI_ESC + PKK_ANSI_RED
ansi2 = "" ansi2 = ""
show_args = True
elif tag == "replace": elif tag == "replace":
sep = ">" sep = ">"
ansi1 = ansi2 = PKK_ANSI_ESC + PKK_ANSI_BOLD ansi1 = ansi2 = PKK_ANSI_ESC + PKK_ANSI_BOLD
show_args = True
else: else:
pkk_fatal(f"Internal error, unsupported difflib.SequenceMatcher operation '{tag}'.") pkk_fatal(f"Internal error, unsupported difflib.SequenceMatcher operation '{tag}'.")
@@ -363,6 +370,7 @@ if __name__ == "__main__":
ansisep = PKK_ANSI_ESC + PKK_ANSI_PURPLE ansisep = PKK_ANSI_ESC + PKK_ANSI_PURPLE
ansiend = PKK_ANSI_ESC + PKK_ANSI_NORMAL ansiend = PKK_ANSI_ESC + PKK_ANSI_NORMAL
# Print out the block # Print out the block
ncall1 = start1 ncall1 = start1
ncall2 = start2 ncall2 = start2
@@ -370,7 +378,7 @@ if __name__ == "__main__":
while True: while True:
# Get line data # Get line data
if ncall1 < end1: if ncall1 < end1:
printer.entry_start() printer.entry_start(show_args)
stack1[ncall1].visit(printer) stack1[ncall1].visit(printer)
data1 = printer.entry_get() data1 = printer.entry_get()
ncall1 += 1 ncall1 += 1
@@ -379,7 +387,7 @@ if __name__ == "__main__":
last1 = True last1 = True
if ncall2 < end2: if ncall2 < end2:
printer.entry_start() printer.entry_start(show_args)
stack2[ncall2].visit(printer) stack2[ncall2].visit(printer)
data2 = printer.entry_get() data2 = printer.entry_get()
ncall2 += 1 ncall2 += 1
@@ -420,3 +428,8 @@ if __name__ == "__main__":
rstrip()) rstrip())
nline += 1 nline += 1
if tag == "equal" and options.suppress_common:
print("[...]")
prevtag = tag