summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorJose Fonseca <jfonseca@vmware.com>2015-06-24 11:07:28 +0100
committerJose Fonseca <jfonseca@vmware.com>2015-06-24 11:33:59 +0100
commitd587885d2ec9a3d4d5b0e424c89966f796ddc6f7 (patch)
treefabab0f4fc47d03af02972f4993acd81777a0cc1 /scripts
parentf3474cc2666c4755b0d48356d5dfc076b50379fe (diff)
scripts/tracediff: Allow to suppress common lines.
And cleanup.
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/tracediff.py77
1 files changed, 51 insertions, 26 deletions
diff --git a/scripts/tracediff.py b/scripts/tracediff.py
index ed61e39d..4480c05a 100755
--- a/scripts/tracediff.py
+++ b/scripts/tracediff.py
@@ -48,10 +48,10 @@ class Differ:
self.apitrace = apitrace
self.isatty = sys.stdout.isatty()
- def setRefTrace(self, ref_trace, ref_calls):
+ def setRefTrace(self, refTrace, ref_calls):
raise NotImplementedError
- def setSrcTrace(self, src_trace, src_calls):
+ def setSrcTrace(self, srcTrace, src_calls):
raise NotImplementedError
def diff(self):
@@ -99,18 +99,34 @@ class ExternalDiffer(Differ):
start_insert = '\33[32m'
end_insert = '\33[0m'
- def __init__(self, apitrace, tool, width=None, callNos = False):
+ def __init__(self, apitrace, options):
Differ.__init__(self, apitrace)
+ tool = options.tool
+ callNos = options.callNos
+
self.diff_args = [tool]
if tool == 'diff':
self.diff_args += [
'--speed-large-files',
]
if self.isatty:
+ if options.suppressCommonLines:
+ self.diff_args += ['--unchanged-line-format=']
+ else:
+ self.diff_args += ['--unchanged-line-format=%l\n']
self.diff_args += [
'--old-line-format=' + self.start_delete + '%l' + self.end_delete + '\n',
'--new-line-format=' + self.start_insert + '%l' + self.end_insert + '\n',
]
+ else:
+ if options.suppressCommonLines:
+ self.diff_args += ['--unchanged-line-format=']
+ else:
+ self.diff_args += ['--unchanged-line-format= %l\n']
+ self.diff_args += [
+ '--old-line-format=- %l\n',
+ '--new-line-format=+ %l\n',
+ ]
elif tool == 'sdiff':
if width is None:
import curses
@@ -136,11 +152,11 @@ class ExternalDiffer(Differ):
assert False
self.callNos = callNos
- def setRefTrace(self, ref_trace, ref_calls):
- self.ref_dumper = AsciiDumper(self.apitrace, ref_trace, ref_calls, self.callNos)
+ def setRefTrace(self, refTrace, ref_calls):
+ self.ref_dumper = AsciiDumper(self.apitrace, refTrace, ref_calls, self.callNos)
- def setSrcTrace(self, src_trace, src_calls):
- self.src_dumper = AsciiDumper(self.apitrace, src_trace, src_calls, self.callNos)
+ def setSrcTrace(self, srcTrace, src_calls):
+ self.src_dumper = AsciiDumper(self.apitrace, srcTrace, src_calls, self.callNos)
def diff(self):
diff_args = self.diff_args + [
@@ -240,7 +256,7 @@ class Loader(Unpickler):
class PythonDiffer(Differ):
- def __init__(self, apitrace, callNos = False):
+ def __init__(self, apitrace, options):
Differ.__init__(self, apitrace)
self.a = None
self.b = None
@@ -250,16 +266,17 @@ class PythonDiffer(Differ):
self.highlighter = PlainHighlighter()
self.delete_color = self.highlighter.red
self.insert_color = self.highlighter.green
- self.callNos = callNos
+ self.callNos = options.callNos
+ self.suppressCommonLines = options.suppressCommonLines
self.aSpace = 0
self.bSpace = 0
self.dumper = Dumper()
- def setRefTrace(self, ref_trace, ref_calls):
- self.a = self.readTrace(ref_trace, ref_calls)
+ def setRefTrace(self, refTrace, ref_calls):
+ self.a = self.readTrace(refTrace, ref_calls)
- def setSrcTrace(self, src_trace, src_calls):
- self.b = self.readTrace(src_trace, src_calls)
+ def setSrcTrace(self, srcTrace, src_calls):
+ self.b = self.readTrace(srcTrace, src_calls)
def readTrace(self, trace, calls):
p = subprocess.Popen(
@@ -375,7 +392,7 @@ class PythonDiffer(Differ):
self.highlighter.color(self.delete_color)
self.highlighter.write(self.dumper.visit(a))
self.highlighter.normal()
- self.highlighter.write(" ")
+ self.highlighter.write(" -> ")
self.highlighter.color(self.insert_color)
self.highlighter.write(self.dumper.visit(b))
self.highlighter.normal()
@@ -404,6 +421,8 @@ class PythonDiffer(Differ):
self.dumpCall(call)
def equal(self, alo, ahi, blo, bhi):
+ if self.suppressCommonLines:
+ return
assert alo < ahi and blo < bhi
assert ahi - alo == bhi - blo
for i in xrange(0, bhi - blo):
@@ -504,18 +523,23 @@ def main():
help="calls to compare [default: %default]")
optparser.add_option(
'--ref-calls', metavar='CALLSET',
- type="string", dest="ref_calls", default=None,
+ type="string", dest="refCalls", default=None,
help="calls to compare from reference trace")
optparser.add_option(
'--src-calls', metavar='CALLSET',
- type="string", dest="src_calls", default=None,
+ type="string", dest="srcCalls", default=None,
help="calls to compare from source trace")
optparser.add_option(
'--call-nos',
action="store_true",
- dest="call_nos", default=False,
+ dest="callNos", default=False,
help="dump call numbers")
optparser.add_option(
+ '--suppress-common-lines',
+ action="store_true",
+ dest="suppressCommonLines", default=False,
+ help="do not output common lines")
+ optparser.add_option(
'-w', '--width', metavar='NUM',
type="int", dest="width",
help="columns [default: auto]")
@@ -538,19 +562,20 @@ def main():
sys.stderr.write('warning: sdiff not found\n')
options.tool = 'diff'
- if options.ref_calls is None:
- options.ref_calls = options.calls
- if options.src_calls is None:
- options.src_calls = options.calls
+ if options.refCalls is None:
+ options.refCalls = options.calls
+ if options.srcCalls is None:
+ options.srcCalls = options.calls
- ref_trace, src_trace = args
+ refTrace, srcTrace = args
if options.tool == 'python':
- differ = PythonDiffer(options.apitrace, options.call_nos)
+ factory = PythonDiffer
else:
- differ = ExternalDiffer(options.apitrace, options.tool, options.width, options.call_nos)
- differ.setRefTrace(ref_trace, options.ref_calls)
- differ.setSrcTrace(src_trace, options.src_calls)
+ factory = ExternalDiffer
+ differ = factory(options.apitrace, options)
+ differ.setRefTrace(refTrace, options.refCalls)
+ differ.setSrcTrace(srcTrace, options.srcCalls)
differ.diff()