tracediff revision 3370
16157Snate@binkert.org#! /usr/bin/env perl
26157Snate@binkert.org# Copyright (c) 2003-2006 The Regents of The University of Michigan
36157Snate@binkert.org# All rights reserved.
46157Snate@binkert.org#
56157Snate@binkert.org# Redistribution and use in source and binary forms, with or without
66157Snate@binkert.org# modification, are permitted provided that the following conditions are
76157Snate@binkert.org# met: redistributions of source code must retain the above copyright
86157Snate@binkert.org# notice, this list of conditions and the following disclaimer;
96157Snate@binkert.org# redistributions in binary form must reproduce the above copyright
106157Snate@binkert.org# notice, this list of conditions and the following disclaimer in the
116157Snate@binkert.org# documentation and/or other materials provided with the distribution;
126157Snate@binkert.org# neither the name of the copyright holders nor the names of its
136157Snate@binkert.org# contributors may be used to endorse or promote products derived from
146157Snate@binkert.org# this software without specific prior written permission.
156157Snate@binkert.org#
166157Snate@binkert.org# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
176157Snate@binkert.org# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
186157Snate@binkert.org# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
196157Snate@binkert.org# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
206157Snate@binkert.org# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
216157Snate@binkert.org# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
226157Snate@binkert.org# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
236157Snate@binkert.org# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
246157Snate@binkert.org# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
256157Snate@binkert.org# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
266157Snate@binkert.org# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
276157Snate@binkert.org#
286157Snate@binkert.org# Authors: Steve Reinhardt
296157Snate@binkert.org
306157Snate@binkert.org# Script to simplify using rundiff on trace outputs from two
316157Snate@binkert.org# invocations of m5.
326157Snate@binkert.org#
336157Snate@binkert.org# ******Note that you need to enable some trace flags in the args in order
346657Snate@binkert.org# to do anything useful!******
356157Snate@binkert.org#
366157Snate@binkert.org# Script arguments are handled uniformly as follows:
376157Snate@binkert.org# - If the argument does not contain a '|' character, it is appended
386168Snate@binkert.org#   to both command lines.
396168Snate@binkert.org# - If the argument has a '|' character in it, the text on either side
406168Snate@binkert.org#   of the '|' is appended to the respective command lines.  Note that
416157Snate@binkert.org#   you'll have to quote the arg or escape the '|' with a backslash
426157Snate@binkert.org#   so that the shell doesn't think you're doing a pipe.
436657Snate@binkert.org#
446657Snate@binkert.org# In other words, the arguments should look like the command line you
456657Snate@binkert.org# want to run, with "|" used to list the alternatives for the parts
466657Snate@binkert.org# that you want to differ between the two runs.
476657Snate@binkert.org#
486657Snate@binkert.org# For example:
496657Snate@binkert.org#
506657Snate@binkert.org# % tracediff m5.opt --opt1 "--opt2|--opt3" --opt4
516657Snate@binkert.org# would compare these two runs:
526657Snate@binkert.org# m5.opt --opt1 --opt2 --opt4
536157Snate@binkert.org# m5.opt --opt1 --opt3 --opt4
546157Snate@binkert.org#
556157Snate@binkert.org# If you want to compare two different simulator binaries, put a '|'
566157Snate@binkert.org# in the first script argument ("path1/m5.opt|path2/m5.opt").  If you
576657Snate@binkert.org# want to add arguments to one run only, just put a '|' in with text
586657Snate@binkert.org# only on one side ("--onlyOn1|").  You can do this with multiple
596657Snate@binkert.org# arguments together too ("|-a -b -c" adds three args to the second
606878Ssteve.reinhardt@amd.com# run only).
616657Snate@binkert.org#
626657Snate@binkert.org
636657Snate@binkert.orgif (@ARGV < 2) {
646657Snate@binkert.org    die "Usage: tracediff \"sim1|sim2\" [common-arg \"arg1|arg2\" ...]\n";
656657Snate@binkert.org}
666999Snate@binkert.org
676657Snate@binkert.orgforeach $arg (@ARGV) {
686999Snate@binkert.org    @pair = split('\|', $arg, -1); # -1 enables null trailing fields
696657Snate@binkert.org    if ($#pair > 0) {
706657Snate@binkert.org	push @cmd1, $pair[0];
716657Snate@binkert.org	push @cmd2, $pair[1];
726657Snate@binkert.org    } else {
736714Ssteve.reinhardt@amd.com	push @cmd1, $arg;
746877Ssteve.reinhardt@amd.com	push @cmd2, $arg;
756877Ssteve.reinhardt@amd.com    }
766877Ssteve.reinhardt@amd.com}
776877Ssteve.reinhardt@amd.com
786877Ssteve.reinhardt@amd.com# First two args are the two simulator binaries to compare
796877Ssteve.reinhardt@amd.com$sim1 = shift @cmd1;
806877Ssteve.reinhardt@amd.com$sim2 = shift @cmd2;
816877Ssteve.reinhardt@amd.com
826877Ssteve.reinhardt@amd.com# Everything else is a simulator arg.
836877Ssteve.reinhardt@amd.com$args1 = join(' ', @cmd1);
846877Ssteve.reinhardt@amd.com$args2 = join(' ', @cmd2);
856877Ssteve.reinhardt@amd.com
866877Ssteve.reinhardt@amd.com# Common mistake: if you don't set any traceflags this often isn't
876877Ssteve.reinhardt@amd.com# doing what you want.
886877Ssteve.reinhardt@amd.comif ($args1 !~ /--trace-flags/) {
896877Ssteve.reinhardt@amd.com    print "****\n";
906877Ssteve.reinhardt@amd.com    print "**** WARNING: no trace flags set... you may not be diffing much!\n";
916925SBrad.Beckmann@amd.com    print "****\n";
926925SBrad.Beckmann@amd.com}
936925SBrad.Beckmann@amd.com
946925SBrad.Beckmann@amd.com# Run individual invocations in separate dirs so output and intermediate
956925SBrad.Beckmann@amd.com# files (particularly config.py and config.ini) don't conflict.
966657Snate@binkert.org$dir1 = "tracediff-$$-1";
976657Snate@binkert.org$dir2 = "tracediff-$$-2";
986657Snate@binkert.orgmkdir($dir1) or die "Can't create dir $dir1\n";
996657Snate@binkert.orgmkdir($dir2) or die "Can't create dir $dir2\n";
1006157Snate@binkert.org
1016157Snate@binkert.org$cmd1 = "$sim1 -d $dir1 $args1 2>&1 |";
1026157Snate@binkert.org$cmd2 = "$sim2 -d $dir2 $args2 2>&1 |";
1036157Snate@binkert.org
1046157Snate@binkert.org# This only works if you have rundiff in your path.  I just edit it
1056157Snate@binkert.org# with an explicit path if necessary.
1066157Snate@binkert.org$fullcmd = "rundiff '$cmd1' '$cmd2' 2>&1 > tracediff-$$.out";
1076157Snate@binkert.org
1086999Snate@binkert.orgprint "Executing $fullcmd\n";
1096657Snate@binkert.orgsystem($fullcmd);
1106657Snate@binkert.org
1116286Snate@binkert.org
1126657Snate@binkert.org
1136657Snate@binkert.org