2 ##########################################################################
4 # Copyright 2011 Jose Fonseca
7 # Permission is hereby granted, free of charge, to any person obtaining a copy
8 # of this software and associated documentation files (the "Software"), to deal
9 # in the Software without restriction, including without limitation the rights
10 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 # copies of the Software, and to permit persons to whom the Software is
12 # furnished to do so, subject to the following conditions:
14 # The above copyright notice and this permission notice shall be included in
15 # all copies or substantial portions of the Software.
17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 ##########################################################################/
38 def stripdump(trace, fifo):
39 dump = subprocess.Popen(
45 '--calls=' + options.calls,
48 stdout = subprocess.PIPE,
49 universal_newlines = True,
52 sed = subprocess.Popen(
56 '-e', r's/^[0-9]\+ //',
57 '-e', r's/hdc = \w\+/hdc/g',
60 stdout = open(fifo, 'wt'),
61 universal_newlines = True,
64 # XXX: Avoid a weird race condition
69 fifodir = tempfile.mkdtemp()
72 for i in range(len(traces)):
74 fifo = os.path.join(fifodir, str(i))
75 stripdump(trace, fifo)
78 # TODO use difflib instead
79 sdiff = subprocess.Popen(
82 '--width=%u' % options.width,
83 '--speed-large-files',
85 stdout = subprocess.PIPE,
86 universal_newlines = True,
89 less = subprocess.Popen(
90 args = ['less', '-FRXn'],
97 shutil.rmtree(fifodir)
103 return curses.tigetnum('cols')
110 default_width = columns()
112 # Parse command line options
113 optparser = optparse.OptionParser(
114 usage='\n\t%prog [options] -- TRACE_FILE TRACE_FILE',
116 optparser.add_option(
117 '-a', '--apitrace', metavar='PROGRAM',
118 type='string', dest='apitrace', default='apitrace',
119 help='apitrace command [default: %default]')
120 optparser.add_option(
121 '-c', '--calls', metavar='CALLSET',
122 type="string", dest="calls", default='1-10000',
123 help="calls to compare [default: %default]")
124 optparser.add_option(
125 '-w', '--width', metavar='NUM',
126 type="string", dest="width", default=default_width,
127 help="columns [default: %default]")
130 (options, args) = optparser.parse_args(sys.argv[1:])
132 optparser.error("incorrect number of arguments")
137 if __name__ == '__main__':