tracediff revision 4018
112137Sar4jc@virginia.edu#! /usr/bin/env perl
212137Sar4jc@virginia.edu# Copyright (c) 2003-2007 The Regents of The University of Michigan
312137Sar4jc@virginia.edu# All rights reserved.
412137Sar4jc@virginia.edu#
512137Sar4jc@virginia.edu# Redistribution and use in source and binary forms, with or without
612137Sar4jc@virginia.edu# modification, are permitted provided that the following conditions are
712137Sar4jc@virginia.edu# met: redistributions of source code must retain the above copyright
812137Sar4jc@virginia.edu# notice, this list of conditions and the following disclaimer;
912137Sar4jc@virginia.edu# redistributions in binary form must reproduce the above copyright
1012137Sar4jc@virginia.edu# notice, this list of conditions and the following disclaimer in the
1112137Sar4jc@virginia.edu# documentation and/or other materials provided with the distribution;
1212137Sar4jc@virginia.edu# neither the name of the copyright holders nor the names of its
1312137Sar4jc@virginia.edu# contributors may be used to endorse or promote products derived from
1412137Sar4jc@virginia.edu# this software without specific prior written permission.
1512137Sar4jc@virginia.edu#
1612137Sar4jc@virginia.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1712137Sar4jc@virginia.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1812137Sar4jc@virginia.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1912137Sar4jc@virginia.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2012137Sar4jc@virginia.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2112137Sar4jc@virginia.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2212137Sar4jc@virginia.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2312137Sar4jc@virginia.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2412137Sar4jc@virginia.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2512137Sar4jc@virginia.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2612137Sar4jc@virginia.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2712137Sar4jc@virginia.edu#
2812137Sar4jc@virginia.edu# Authors: Steve Reinhardt
2912137Sar4jc@virginia.edu
3012137Sar4jc@virginia.edu# Script to simplify using rundiff on trace outputs from two
3112137Sar4jc@virginia.edu# invocations of m5.
3212137Sar4jc@virginia.edu#
3312137Sar4jc@virginia.edu# ******Note that you need to enable some trace flags in the args in order
3412137Sar4jc@virginia.edu# to do anything useful!******
3512137Sar4jc@virginia.edu#
3612137Sar4jc@virginia.edu# Script arguments are handled uniformly as follows:
3712137Sar4jc@virginia.edu# - If the argument does not contain a '|' character, it is appended
3812137Sar4jc@virginia.edu#   to both command lines.
3912137Sar4jc@virginia.edu# - If the argument has a '|' character in it, the text on either side
4012137Sar4jc@virginia.edu#   of the '|' is appended to the respective command lines.  Note that
4112137Sar4jc@virginia.edu#   you'll have to quote the arg or escape the '|' with a backslash
4212137Sar4jc@virginia.edu#   so that the shell doesn't think you're doing a pipe.
4312137Sar4jc@virginia.edu#
4412137Sar4jc@virginia.edu# In other words, the arguments should look like the command line you
4512137Sar4jc@virginia.edu# want to run, with "|" used to list the alternatives for the parts
4612137Sar4jc@virginia.edu# that you want to differ between the two runs.
4712137Sar4jc@virginia.edu#
4812137Sar4jc@virginia.edu# For example:
4912137Sar4jc@virginia.edu#
5012137Sar4jc@virginia.edu# % tracediff m5.opt --opt1 "--opt2|--opt3" --opt4
5112137Sar4jc@virginia.edu# would compare these two runs:
5212137Sar4jc@virginia.edu# m5.opt --opt1 --opt2 --opt4
5312137Sar4jc@virginia.edu# m5.opt --opt1 --opt3 --opt4
5412137Sar4jc@virginia.edu#
5512137Sar4jc@virginia.edu# If you want to compare two different simulator binaries, put a '|'
5612137Sar4jc@virginia.edu# in the first script argument ("path1/m5.opt|path2/m5.opt").  If you
5712137Sar4jc@virginia.edu# want to add arguments to one run only, just put a '|' in with text
5812137Sar4jc@virginia.edu# only on one side ("--onlyOn1|").  You can do this with multiple
5912137Sar4jc@virginia.edu# arguments together too ("|-a -b -c" adds three args to the second
6012137Sar4jc@virginia.edu# run only).
6112137Sar4jc@virginia.edu#
6212137Sar4jc@virginia.edu
6312137Sar4jc@virginia.eduuse FindBin;
6412137Sar4jc@virginia.edu
6512137Sar4jc@virginia.eduif (@ARGV < 2) {
6612137Sar4jc@virginia.edu    die "Usage: tracediff \"sim1|sim2\" [common-arg \"arg1|arg2\" ...]\n";
6712137Sar4jc@virginia.edu}
6812137Sar4jc@virginia.edu
6912137Sar4jc@virginia.eduforeach $arg (@ARGV) {
7012137Sar4jc@virginia.edu    @pair = split('\|', $arg, -1); # -1 enables null trailing fields
7112137Sar4jc@virginia.edu    if ($#pair > 0) {
7212137Sar4jc@virginia.edu	push @cmd1, $pair[0];
7312137Sar4jc@virginia.edu	push @cmd2, $pair[1];
7412137Sar4jc@virginia.edu    } else {
7512137Sar4jc@virginia.edu	push @cmd1, $arg;
7612137Sar4jc@virginia.edu	push @cmd2, $arg;
7712137Sar4jc@virginia.edu    }
7812137Sar4jc@virginia.edu}
7912137Sar4jc@virginia.edu
8012137Sar4jc@virginia.edu# First two args are the two simulator binaries to compare
8112137Sar4jc@virginia.edu$sim1 = shift @cmd1;
8212137Sar4jc@virginia.edu$sim2 = shift @cmd2;
8312137Sar4jc@virginia.edu
8412137Sar4jc@virginia.edu# Everything else is a simulator arg.
8512137Sar4jc@virginia.edu$args1 = join(' ', @cmd1);
8612137Sar4jc@virginia.edu$args2 = join(' ', @cmd2);
8712137Sar4jc@virginia.edu
8812137Sar4jc@virginia.edu# Common mistake: if you don't set any traceflags this often isn't
8912137Sar4jc@virginia.edu# doing what you want.
9012137Sar4jc@virginia.eduif ($args1 !~ /--trace-flags/) {
9112137Sar4jc@virginia.edu    print "****\n";
9212137Sar4jc@virginia.edu    print "**** WARNING: no trace flags set... you may not be diffing much!\n";
9312137Sar4jc@virginia.edu    print "****\n";
9412137Sar4jc@virginia.edu}
9512137Sar4jc@virginia.edu
9612137Sar4jc@virginia.edu# Run individual invocations in separate dirs so output and intermediate
9712137Sar4jc@virginia.edu# files (particularly config.py and config.ini) don't conflict.
9812137Sar4jc@virginia.edu$dir1 = "tracediff-$$-1";
9912137Sar4jc@virginia.edu$dir2 = "tracediff-$$-2";
10012137Sar4jc@virginia.edumkdir($dir1) or die "Can't create dir $dir1\n";
10112137Sar4jc@virginia.edumkdir($dir2) or die "Can't create dir $dir2\n";
10212137Sar4jc@virginia.edu
10312137Sar4jc@virginia.edu$cmd1 = "$sim1 -d $dir1 $args1 2>&1 |";
10412137Sar4jc@virginia.edu$cmd2 = "$sim2 -d $dir2 $args2 2>&1 |";
10512137Sar4jc@virginia.edu
10612137Sar4jc@virginia.edu# Expect that rundiff is in the same dir as the tracediff script.
10712137Sar4jc@virginia.edu# FindBin figures that out for us.
10812137Sar4jc@virginia.edu$fullcmd = "$FindBin::Bin/rundiff '$cmd1' '$cmd2' 2>&1 > tracediff-$$.out";
10912137Sar4jc@virginia.edu
11012137Sar4jc@virginia.eduprint "Executing $fullcmd\n";
11112137Sar4jc@virginia.edusystem($fullcmd);
11212137Sar4jc@virginia.edu
11312137Sar4jc@virginia.edu
11412137Sar4jc@virginia.edu
11512137Sar4jc@virginia.edu