tracediff revision 4018
12929Sktlim@umich.edu#! /usr/bin/env perl
22929Sktlim@umich.edu# Copyright (c) 2003-2007 The Regents of The University of Michigan
32932Sktlim@umich.edu# All rights reserved.
42929Sktlim@umich.edu#
52929Sktlim@umich.edu# Redistribution and use in source and binary forms, with or without
62929Sktlim@umich.edu# modification, are permitted provided that the following conditions are
72929Sktlim@umich.edu# met: redistributions of source code must retain the above copyright
82929Sktlim@umich.edu# notice, this list of conditions and the following disclaimer;
92929Sktlim@umich.edu# redistributions in binary form must reproduce the above copyright
102929Sktlim@umich.edu# notice, this list of conditions and the following disclaimer in the
112929Sktlim@umich.edu# documentation and/or other materials provided with the distribution;
122929Sktlim@umich.edu# neither the name of the copyright holders nor the names of its
132929Sktlim@umich.edu# contributors may be used to endorse or promote products derived from
142929Sktlim@umich.edu# this software without specific prior written permission.
152929Sktlim@umich.edu#
162929Sktlim@umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172929Sktlim@umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182929Sktlim@umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192929Sktlim@umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202929Sktlim@umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212929Sktlim@umich.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222929Sktlim@umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232929Sktlim@umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242929Sktlim@umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252929Sktlim@umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262929Sktlim@umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272929Sktlim@umich.edu#
282932Sktlim@umich.edu# Authors: Steve Reinhardt
292932Sktlim@umich.edu
302932Sktlim@umich.edu# Script to simplify using rundiff on trace outputs from two
312929Sktlim@umich.edu# invocations of m5.
326007Ssteve.reinhardt@amd.com#
337735SAli.Saidi@ARM.com# ******Note that you need to enable some trace flags in the args in order
342929Sktlim@umich.edu# to do anything useful!******
352929Sktlim@umich.edu#
362929Sktlim@umich.edu# Script arguments are handled uniformly as follows:
372929Sktlim@umich.edu# - If the argument does not contain a '|' character, it is appended
382929Sktlim@umich.edu#   to both command lines.
392929Sktlim@umich.edu# - If the argument has a '|' character in it, the text on either side
402929Sktlim@umich.edu#   of the '|' is appended to the respective command lines.  Note that
412929Sktlim@umich.edu#   you'll have to quote the arg or escape the '|' with a backslash
422929Sktlim@umich.edu#   so that the shell doesn't think you're doing a pipe.
432929Sktlim@umich.edu#
442929Sktlim@umich.edu# In other words, the arguments should look like the command line you
452929Sktlim@umich.edu# want to run, with "|" used to list the alternatives for the parts
462929Sktlim@umich.edu# that you want to differ between the two runs.
476007Ssteve.reinhardt@amd.com#
486007Ssteve.reinhardt@amd.com# For example:
496007Ssteve.reinhardt@amd.com#
506007Ssteve.reinhardt@amd.com# % tracediff m5.opt --opt1 "--opt2|--opt3" --opt4
516007Ssteve.reinhardt@amd.com# would compare these two runs:
526007Ssteve.reinhardt@amd.com# m5.opt --opt1 --opt2 --opt4
536007Ssteve.reinhardt@amd.com# m5.opt --opt1 --opt3 --opt4
546007Ssteve.reinhardt@amd.com#
556007Ssteve.reinhardt@amd.com# If you want to compare two different simulator binaries, put a '|'
566007Ssteve.reinhardt@amd.com# in the first script argument ("path1/m5.opt|path2/m5.opt").  If you
576007Ssteve.reinhardt@amd.com# want to add arguments to one run only, just put a '|' in with text
586007Ssteve.reinhardt@amd.com# only on one side ("--onlyOn1|").  You can do this with multiple
596007Ssteve.reinhardt@amd.com# arguments together too ("|-a -b -c" adds three args to the second
606007Ssteve.reinhardt@amd.com# run only).
616007Ssteve.reinhardt@amd.com#
626007Ssteve.reinhardt@amd.com
636007Ssteve.reinhardt@amd.comuse FindBin;
646007Ssteve.reinhardt@amd.com
656007Ssteve.reinhardt@amd.comif (@ARGV < 2) {
666007Ssteve.reinhardt@amd.com    die "Usage: tracediff \"sim1|sim2\" [common-arg \"arg1|arg2\" ...]\n";
676007Ssteve.reinhardt@amd.com}
686007Ssteve.reinhardt@amd.com
696007Ssteve.reinhardt@amd.comforeach $arg (@ARGV) {
706007Ssteve.reinhardt@amd.com    @pair = split('\|', $arg, -1); # -1 enables null trailing fields
716007Ssteve.reinhardt@amd.com    if ($#pair > 0) {
726007Ssteve.reinhardt@amd.com	push @cmd1, $pair[0];
736007Ssteve.reinhardt@amd.com	push @cmd2, $pair[1];
746007Ssteve.reinhardt@amd.com    } else {
756007Ssteve.reinhardt@amd.com	push @cmd1, $arg;
762929Sktlim@umich.edu	push @cmd2, $arg;
772929Sktlim@umich.edu    }
782929Sktlim@umich.edu}
796007Ssteve.reinhardt@amd.com
806007Ssteve.reinhardt@amd.com# First two args are the two simulator binaries to compare
816007Ssteve.reinhardt@amd.com$sim1 = shift @cmd1;
826007Ssteve.reinhardt@amd.com$sim2 = shift @cmd2;
836007Ssteve.reinhardt@amd.com
846007Ssteve.reinhardt@amd.com# Everything else is a simulator arg.
852929Sktlim@umich.edu$args1 = join(' ', @cmd1);
862929Sktlim@umich.edu$args2 = join(' ', @cmd2);
872929Sktlim@umich.edu
882929Sktlim@umich.edu# Common mistake: if you don't set any traceflags this often isn't
892929Sktlim@umich.edu# doing what you want.
906011Ssteve.reinhardt@amd.comif ($args1 !~ /--trace-flags/) {
916007Ssteve.reinhardt@amd.com    print "****\n";
926007Ssteve.reinhardt@amd.com    print "**** WARNING: no trace flags set... you may not be diffing much!\n";
936007Ssteve.reinhardt@amd.com    print "****\n";
946007Ssteve.reinhardt@amd.com}
956007Ssteve.reinhardt@amd.com
966007Ssteve.reinhardt@amd.com# Run individual invocations in separate dirs so output and intermediate
976007Ssteve.reinhardt@amd.com# files (particularly config.py and config.ini) don't conflict.
986007Ssteve.reinhardt@amd.com$dir1 = "tracediff-$$-1";
996007Ssteve.reinhardt@amd.com$dir2 = "tracediff-$$-2";
1006007Ssteve.reinhardt@amd.commkdir($dir1) or die "Can't create dir $dir1\n";
1016007Ssteve.reinhardt@amd.commkdir($dir2) or die "Can't create dir $dir2\n";
1026007Ssteve.reinhardt@amd.com
1036007Ssteve.reinhardt@amd.com$cmd1 = "$sim1 -d $dir1 $args1 2>&1 |";
1046007Ssteve.reinhardt@amd.com$cmd2 = "$sim2 -d $dir2 $args2 2>&1 |";
1057735SAli.Saidi@ARM.com
1066011Ssteve.reinhardt@amd.com# Expect that rundiff is in the same dir as the tracediff script.
1076007Ssteve.reinhardt@amd.com# FindBin figures that out for us.
1086007Ssteve.reinhardt@amd.com$fullcmd = "$FindBin::Bin/rundiff '$cmd1' '$cmd2' 2>&1 > tracediff-$$.out";
1096007Ssteve.reinhardt@amd.com
1106007Ssteve.reinhardt@amd.comprint "Executing $fullcmd\n";
1117735SAli.Saidi@ARM.comsystem($fullcmd);
1127735SAli.Saidi@ARM.com
1137735SAli.Saidi@ARM.com
1147735SAli.Saidi@ARM.com
1157735SAli.Saidi@ARM.com