2 # Copyright (c) 2003-2007 The Regents of The University of Michigan
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are
7 # met: redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer;
9 # redistributions in binary form must reproduce the above copyright
10 # notice, this list of conditions and the following disclaimer in the
11 # documentation and/or other materials provided with the distribution;
12 # neither the name of the copyright holders nor the names of its
13 # contributors may be used to endorse or promote products derived from
14 # this software without specific prior written permission.
16 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 # Authors: Steve Reinhardt
30 # Script to simplify using rundiff on trace outputs from two
31 # invocations of m5. Takes a common m5 command line with embedded
32 # alternatives and executes the two alternative commands in separate
33 # subdirectories with output piped to rundiff.
35 # ******Note that you need to enable some trace flags in the args in order
36 # to do anything useful!******
38 # Script arguments are handled uniformly as follows:
39 # - If the argument does not contain a '|' character, it is appended
40 # to both command lines.
41 # - If the argument has a '|' character in it, the text on either side
42 # of the '|' is appended to the respective command lines. Note that
43 # you'll have to quote the arg or escape the '|' with a backslash
44 # so that the shell doesn't think you're doing a pipe.
45 # - Arguments with '#' characters are split at those characters,
46 # processed for alternatives ('|'s) as independent terms, then
47 # pasted back into a single argument (without the '#'s). (Sort of
48 # inspired by the C preprocessor '##' token pasting operator.)
50 # In other words, the arguments should look like the command line you
51 # want to run, with "|" used to list the alternatives for the parts
52 # that you want to differ between the two runs.
56 # % tracediff m5.opt --opt1 '--opt2|--opt3' --opt4
57 # would compare these two runs:
58 # m5.opt --opt1 --opt2 --opt4
59 # m5.opt --opt1 --opt3 --opt4
61 # % tracediff 'path1|path2#/m5.opt' --opt1 --opt2
62 # would compare these two runs:
63 # path1/m5.opt --opt1 --opt2
64 # path2/m5.opt --opt1 --opt2
66 # If you want to add arguments to one run only, just put a '|' in with
67 # text only on one side ('--onlyOn1|'). You can do this with multiple
68 # arguments together too ('|-a -b -c' adds three args to the second
71 # The '-n' argument to tracediff allows you to preview the two
72 # generated command lines without running them.
79 if (@ARGV >= 1 && $ARGV[0] eq '-n') {
85 die "Usage: tracediff [-n] \"sim1|sim2\" [common-arg \"arg1|arg2\" ...]\n";
88 foreach $arg (@ARGV) {
90 @subargs = split('#', $arg);
91 foreach $subarg (@subargs) {
95 @pair = split('\|', $subarg, -1); # -1 enables null trailing fields
99 } elsif (@pair == 2) {
103 print 'Parse error: too many |s in ', $arg, "\n";
114 print "CMD1: ", join(' ', @cmd1), "\n";
115 print "CMD2: ", join(' ', @cmd2), "\n";
119 # First two args are the two simulator binaries to compare
123 # Everything else is a simulator arg.
124 $args1 = join(' ', @cmd1);
125 $args2 = join(' ', @cmd2);
127 # Common mistake: if you don't set any traceflags this often isn't
128 # doing what you want.
129 if ($args1 !~ /--trace-flags/) {
131 print "**** WARNING: no trace flags set... you may not be diffing much!\n";
135 # Run individual invocations in separate dirs so output and intermediate
136 # files (particularly config.py and config.ini) don't conflict.
137 $dir1 = "tracediff-$$-1";
138 $dir2 = "tracediff-$$-2";
139 mkdir($dir1) or die "Can't create dir $dir1\n";
140 mkdir($dir2) or die "Can't create dir $dir2\n";
142 $cmd1 = "$sim1 -d $dir1 $args1 2>&1 |";
143 $cmd2 = "$sim2 -d $dir2 $args2 2>&1 |";
145 # Expect that rundiff is in the same dir as the tracediff script.
146 # FindBin figures that out for us.
147 $fullcmd = "$FindBin::Bin/rundiff '$cmd1' '$cmd2' 2>&1 > tracediff-$$.out";
149 print "Executing $fullcmd\n";