tracediff revision 5751
13534Sgblack@eecs.umich.edu#! /usr/bin/env perl
23534Sgblack@eecs.umich.edu# Copyright (c) 2003-2007 The Regents of The University of Michigan
33534Sgblack@eecs.umich.edu# All rights reserved.
43534Sgblack@eecs.umich.edu#
53534Sgblack@eecs.umich.edu# Redistribution and use in source and binary forms, with or without
63534Sgblack@eecs.umich.edu# modification, are permitted provided that the following conditions are
73534Sgblack@eecs.umich.edu# met: redistributions of source code must retain the above copyright
83534Sgblack@eecs.umich.edu# notice, this list of conditions and the following disclaimer;
93534Sgblack@eecs.umich.edu# redistributions in binary form must reproduce the above copyright
103534Sgblack@eecs.umich.edu# notice, this list of conditions and the following disclaimer in the
113534Sgblack@eecs.umich.edu# documentation and/or other materials provided with the distribution;
123534Sgblack@eecs.umich.edu# neither the name of the copyright holders nor the names of its
133534Sgblack@eecs.umich.edu# contributors may be used to endorse or promote products derived from
143534Sgblack@eecs.umich.edu# this software without specific prior written permission.
153534Sgblack@eecs.umich.edu#
163534Sgblack@eecs.umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
173534Sgblack@eecs.umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
183534Sgblack@eecs.umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
193534Sgblack@eecs.umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
203534Sgblack@eecs.umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
213534Sgblack@eecs.umich.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
223534Sgblack@eecs.umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
233534Sgblack@eecs.umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
243534Sgblack@eecs.umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
253534Sgblack@eecs.umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
263534Sgblack@eecs.umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
273534Sgblack@eecs.umich.edu#
283534Sgblack@eecs.umich.edu# Authors: Steve Reinhardt
293534Sgblack@eecs.umich.edu
303534Sgblack@eecs.umich.edu# Script to simplify using rundiff on trace outputs from two
313534Sgblack@eecs.umich.edu# invocations of m5.  Takes a common m5 command line with embedded
324202Sbinkertn@umich.edu# alternatives and executes the two alternative commands in separate
333534Sgblack@eecs.umich.edu# subdirectories with output piped to rundiff.
344202Sbinkertn@umich.edu#
354486Sbinkertn@umich.edu# ******Note that you need to enable some trace flags in the args in order
365794Ssaidi@eecs.umich.edu# to do anything useful!******
374486Sbinkertn@umich.edu#
384486Sbinkertn@umich.edu# Script arguments are handled uniformly as follows:
394486Sbinkertn@umich.edu# - If the argument does not contain a '|' character, it is appended
404486Sbinkertn@umich.edu#   to both command lines.
414486Sbinkertn@umich.edu# - If the argument has a '|' character in it, the text on either side
424486Sbinkertn@umich.edu#   of the '|' is appended to the respective command lines.  Note that
434486Sbinkertn@umich.edu#   you'll have to quote the arg or escape the '|' with a backslash
445478Snate@binkert.org#   so that the shell doesn't think you're doing a pipe.
454486Sbinkertn@umich.edu# - Arguments with '#' characters are split at those characters,
464486Sbinkertn@umich.edu#   processed for alternatives ('|'s) as independent terms, then
474202Sbinkertn@umich.edu#   pasted back into a single argument (without the '#'s).  (Sort of
485794Ssaidi@eecs.umich.edu#   inspired by the C preprocessor '##' token pasting operator.)
494202Sbinkertn@umich.edu#
504202Sbinkertn@umich.edu# In other words, the arguments should look like the command line you
515485Snate@binkert.org# want to run, with "|" used to list the alternatives for the parts
524202Sbinkertn@umich.edu# that you want to differ between the two runs.
534202Sbinkertn@umich.edu#
544202Sbinkertn@umich.edu# For example:
554202Sbinkertn@umich.edu#
564762Snate@binkert.org# % tracediff m5.opt --opt1 '--opt2|--opt3' --opt4
574218Ssaidi@eecs.umich.edu# would compare these two runs:
584202Sbinkertn@umich.edu# m5.opt --opt1 --opt2 --opt4
594202Sbinkertn@umich.edu# m5.opt --opt1 --opt3 --opt4
605443Sgblack@eecs.umich.edu#
614202Sbinkertn@umich.edu# % tracediff 'path1|path2#/m5.opt' --opt1 --opt2
624202Sbinkertn@umich.edu# would compare these two runs:
635392Sgblack@eecs.umich.edu# path1/m5.opt --opt1 --opt2
644202Sbinkertn@umich.edu# path2/m5.opt --opt1 --opt2
654202Sbinkertn@umich.edu#
664202Sbinkertn@umich.edu# If you want to add arguments to one run only, just put a '|' in with
674202Sbinkertn@umich.edu# text only on one side ('--onlyOn1|').  You can do this with multiple
684202Sbinkertn@umich.edu# arguments together too ('|-a -b -c' adds three args to the second
694202Sbinkertn@umich.edu# run only).
704762Snate@binkert.org#
715478Snate@binkert.org# The '-n' argument to tracediff allows you to preview the two
724202Sbinkertn@umich.edu# generated command lines without running them.
734202Sbinkertn@umich.edu#
745192Ssaidi@eecs.umich.edu
755192Ssaidi@eecs.umich.eduuse FindBin;
765192Ssaidi@eecs.umich.edu
775192Ssaidi@eecs.umich.edu$dryrun = 0;
785794Ssaidi@eecs.umich.edu
795192Ssaidi@eecs.umich.eduif (@ARGV >= 1 && $ARGV[0] eq '-n') {
805192Ssaidi@eecs.umich.edu    $dryrun = 1;
815192Ssaidi@eecs.umich.edu    shift @ARGV;
825192Ssaidi@eecs.umich.edu}
835192Ssaidi@eecs.umich.edu
845192Ssaidi@eecs.umich.eduif (@ARGV < 1) {
855192Ssaidi@eecs.umich.edu    die "Usage: tracediff [-n] \"sim1|sim2\" [common-arg \"arg1|arg2\" ...]\n";
865192Ssaidi@eecs.umich.edu}
875192Ssaidi@eecs.umich.edu
885192Ssaidi@eecs.umich.eduforeach $arg (@ARGV) {
895192Ssaidi@eecs.umich.edu    $a1 = $a2 = '';
905443Sgblack@eecs.umich.edu    @subargs = split('#', $arg);
915192Ssaidi@eecs.umich.edu    foreach $subarg (@subargs) {
925392Sgblack@eecs.umich.edu        if ($subarg eq '') {
935192Ssaidi@eecs.umich.edu            next;
945192Ssaidi@eecs.umich.edu        }
955192Ssaidi@eecs.umich.edu        @pair = split('\|', $subarg, -1); # -1 enables null trailing fields
965192Ssaidi@eecs.umich.edu        if (@pair == 1) {
975478Snate@binkert.org            $a1 .= $subarg;
985478Snate@binkert.org            $a2 .= $subarg;
995192Ssaidi@eecs.umich.edu        } elsif (@pair == 2) {
1005192Ssaidi@eecs.umich.edu            $a1 .= $pair[0];
1015192Ssaidi@eecs.umich.edu            $a2 .= $pair[1];
1025192Ssaidi@eecs.umich.edu        } else {
1035192Ssaidi@eecs.umich.edu            print 'Parse error: too many |s in ', $arg, "\n";
1045763Ssaidi@eecs.umich.edu            exit(1);
1055192Ssaidi@eecs.umich.edu        }
1065192Ssaidi@eecs.umich.edu    }
1075192Ssaidi@eecs.umich.edu
1085192Ssaidi@eecs.umich.edu    push @cmd1, $a1;
109    push @cmd2, $a2;
110}
111
112
113if ($dryrun) {
114    print "CMD1: ", join(' ', @cmd1), "\n";
115    print "CMD2: ", join(' ', @cmd2), "\n";
116    exit(0);
117}
118
119# First two args are the two simulator binaries to compare
120$sim1 = shift @cmd1;
121$sim2 = shift @cmd2;
122
123# Everything else is a simulator arg.
124$args1 = join(' ', @cmd1);
125$args2 = join(' ', @cmd2);
126
127# Common mistake: if you don't set any traceflags this often isn't
128# doing what you want.
129if ($args1 !~ /--trace-flags/) {
130    print "****\n";
131    print "**** WARNING: no trace flags set... you may not be diffing much!\n";
132    print "****\n";
133}
134
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";
139mkdir($dir1) or die "Can't create dir $dir1\n";
140mkdir($dir2) or die "Can't create dir $dir2\n";
141
142$cmd1 = "$sim1 -d $dir1 $args1 2>&1 |";
143$cmd2 = "$sim2 -d $dir2 $args2 2>&1 |";
144
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";
148
149print "Executing $fullcmd\n";
150system($fullcmd);
151
152
153
154