tracediff revision 5725
1247Sstever@eecs.umich.edu#! /usr/bin/env perl
24018Sstever@eecs.umich.edu# Copyright (c) 2003-2007 The Regents of The University of Michigan
3247Sstever@eecs.umich.edu# All rights reserved.
4247Sstever@eecs.umich.edu#
5247Sstever@eecs.umich.edu# Redistribution and use in source and binary forms, with or without
6247Sstever@eecs.umich.edu# modification, are permitted provided that the following conditions are
7247Sstever@eecs.umich.edu# met: redistributions of source code must retain the above copyright
8247Sstever@eecs.umich.edu# notice, this list of conditions and the following disclaimer;
9247Sstever@eecs.umich.edu# redistributions in binary form must reproduce the above copyright
10247Sstever@eecs.umich.edu# notice, this list of conditions and the following disclaimer in the
11247Sstever@eecs.umich.edu# documentation and/or other materials provided with the distribution;
12247Sstever@eecs.umich.edu# neither the name of the copyright holders nor the names of its
13247Sstever@eecs.umich.edu# contributors may be used to endorse or promote products derived from
14247Sstever@eecs.umich.edu# this software without specific prior written permission.
15247Sstever@eecs.umich.edu#
16247Sstever@eecs.umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17247Sstever@eecs.umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18247Sstever@eecs.umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19247Sstever@eecs.umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20247Sstever@eecs.umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21247Sstever@eecs.umich.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22247Sstever@eecs.umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23247Sstever@eecs.umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24247Sstever@eecs.umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25247Sstever@eecs.umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26247Sstever@eecs.umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27247Sstever@eecs.umich.edu#
28247Sstever@eecs.umich.edu# Authors: Steve Reinhardt
29247Sstever@eecs.umich.edu
301123Sstever@eecs.umich.edu# Script to simplify using rundiff on trace outputs from two
315725SSteve.Reinhardt@amd.com# invocations of m5.  Takes a common m5 command line with embedded
325725SSteve.Reinhardt@amd.com# alternatives and executes the two alternative commands in separate
335725SSteve.Reinhardt@amd.com# subdirectories with output piped to rundiff.
341123Sstever@eecs.umich.edu#
351746Shsul@eecs.umich.edu# ******Note that you need to enable some trace flags in the args in order
361746Shsul@eecs.umich.edu# to do anything useful!******
371123Sstever@eecs.umich.edu#
383362Sstever@eecs.umich.edu# Script arguments are handled uniformly as follows:
393362Sstever@eecs.umich.edu# - If the argument does not contain a '|' character, it is appended
403362Sstever@eecs.umich.edu#   to both command lines.
413362Sstever@eecs.umich.edu# - If the argument has a '|' character in it, the text on either side
423362Sstever@eecs.umich.edu#   of the '|' is appended to the respective command lines.  Note that
433362Sstever@eecs.umich.edu#   you'll have to quote the arg or escape the '|' with a backslash
443362Sstever@eecs.umich.edu#   so that the shell doesn't think you're doing a pipe.
455725SSteve.Reinhardt@amd.com# - Arguments with '#' characters are split at those characters,
465725SSteve.Reinhardt@amd.com#   processed for alternatives ('|'s) as independent terms, then
475725SSteve.Reinhardt@amd.com#   pasted back into a single argument (without the '#'s).  (Sort of
485725SSteve.Reinhardt@amd.com#   inspired by the C preprocessor '##' token pasting operator.)
491123Sstever@eecs.umich.edu#
503370Sstever@eecs.umich.edu# In other words, the arguments should look like the command line you
513370Sstever@eecs.umich.edu# want to run, with "|" used to list the alternatives for the parts
523370Sstever@eecs.umich.edu# that you want to differ between the two runs.
533370Sstever@eecs.umich.edu#
543362Sstever@eecs.umich.edu# For example:
553362Sstever@eecs.umich.edu#
565725SSteve.Reinhardt@amd.com# % tracediff m5.opt --opt1 '--opt2|--opt3' --opt4
573362Sstever@eecs.umich.edu# would compare these two runs:
583362Sstever@eecs.umich.edu# m5.opt --opt1 --opt2 --opt4
593362Sstever@eecs.umich.edu# m5.opt --opt1 --opt3 --opt4
603362Sstever@eecs.umich.edu#
615725SSteve.Reinhardt@amd.com# % tracediff 'path1|path2#/m5.opt' --opt1 --opt2
625725SSteve.Reinhardt@amd.com# would compare these two runs:
635725SSteve.Reinhardt@amd.com# path1/m5.opt --opt1 --opt2
645725SSteve.Reinhardt@amd.com# path2/m5.opt --opt1 --opt2
655725SSteve.Reinhardt@amd.com#
665725SSteve.Reinhardt@amd.com# If you want to add arguments to one run only, just put a '|' in with
675725SSteve.Reinhardt@amd.com# text only on one side ('--onlyOn1|').  You can do this with multiple
685725SSteve.Reinhardt@amd.com# arguments together too ('|-a -b -c' adds three args to the second
693362Sstever@eecs.umich.edu# run only).
701123Sstever@eecs.umich.edu#
715725SSteve.Reinhardt@amd.com# The '-n' argument to tracediff allows you to preview the two
725725SSteve.Reinhardt@amd.com# generated command lines without running them.
735725SSteve.Reinhardt@amd.com#
74247Sstever@eecs.umich.edu
754018Sstever@eecs.umich.eduuse FindBin;
764018Sstever@eecs.umich.edu
775725SSteve.Reinhardt@amd.com$dryrun = 0;
785725SSteve.Reinhardt@amd.com
795725SSteve.Reinhardt@amd.comif (@ARGV >= 1 && $ARGV[0] eq '-n') {
805725SSteve.Reinhardt@amd.com    $dryrun = 1;
815725SSteve.Reinhardt@amd.com    shift @ARGV;
825725SSteve.Reinhardt@amd.com}
835725SSteve.Reinhardt@amd.com
845725SSteve.Reinhardt@amd.comif (@ARGV < 1) {
855725SSteve.Reinhardt@amd.com    die "Usage: tracediff [-n] \"sim1|sim2\" [common-arg \"arg1|arg2\" ...]\n";
863362Sstever@eecs.umich.edu}
873362Sstever@eecs.umich.edu
883362Sstever@eecs.umich.eduforeach $arg (@ARGV) {
895725SSteve.Reinhardt@amd.com    $a1 = $a2 = '';
905725SSteve.Reinhardt@amd.com    @subargs = split('#', $arg, -1);
915725SSteve.Reinhardt@amd.com    foreach $subarg (@subargs) {
925725SSteve.Reinhardt@amd.com        @pair = split('\|', $subarg, -1); # -1 enables null trailing fields
935725SSteve.Reinhardt@amd.com        if (@pair == 1) {
945725SSteve.Reinhardt@amd.com            $a1 .= $subarg;
955725SSteve.Reinhardt@amd.com            $a2 .= $subarg;
965725SSteve.Reinhardt@amd.com        } elsif (@pair == 2) {
975725SSteve.Reinhardt@amd.com            $a1 .= $pair[0];
985725SSteve.Reinhardt@amd.com            $a2 .= $pair[1];
995725SSteve.Reinhardt@amd.com        } else {
1005725SSteve.Reinhardt@amd.com            print 'Parse error: too many |s in ', $arg, '\n';
1015725SSteve.Reinhardt@amd.com            exit(1);
1025725SSteve.Reinhardt@amd.com        }
1033362Sstever@eecs.umich.edu    }
1045725SSteve.Reinhardt@amd.com
1055725SSteve.Reinhardt@amd.com    push @cmd1, $a1;
1065725SSteve.Reinhardt@amd.com    push @cmd2, $a2;
1075725SSteve.Reinhardt@amd.com}
1085725SSteve.Reinhardt@amd.com
1095725SSteve.Reinhardt@amd.com
1105725SSteve.Reinhardt@amd.comif ($dryrun) {
1115725SSteve.Reinhardt@amd.com    print "CMD1: ", join(' ', @cmd1), "\n";
1125725SSteve.Reinhardt@amd.com    print "CMD2: ", join(' ', @cmd2), "\n";
1135725SSteve.Reinhardt@amd.com    exit(0);
114247Sstever@eecs.umich.edu}
115247Sstever@eecs.umich.edu
116247Sstever@eecs.umich.edu# First two args are the two simulator binaries to compare
1173362Sstever@eecs.umich.edu$sim1 = shift @cmd1;
1183362Sstever@eecs.umich.edu$sim2 = shift @cmd2;
119247Sstever@eecs.umich.edu
1203362Sstever@eecs.umich.edu# Everything else is a simulator arg.
1213362Sstever@eecs.umich.edu$args1 = join(' ', @cmd1);
1223362Sstever@eecs.umich.edu$args2 = join(' ', @cmd2);
123247Sstever@eecs.umich.edu
1243370Sstever@eecs.umich.edu# Common mistake: if you don't set any traceflags this often isn't
1253370Sstever@eecs.umich.edu# doing what you want.
1263370Sstever@eecs.umich.eduif ($args1 !~ /--trace-flags/) {
1273370Sstever@eecs.umich.edu    print "****\n";
1283370Sstever@eecs.umich.edu    print "**** WARNING: no trace flags set... you may not be diffing much!\n";
1293370Sstever@eecs.umich.edu    print "****\n";
1303370Sstever@eecs.umich.edu}
1313370Sstever@eecs.umich.edu
1321442Sstever@eecs.umich.edu# Run individual invocations in separate dirs so output and intermediate
1331442Sstever@eecs.umich.edu# files (particularly config.py and config.ini) don't conflict.
1341442Sstever@eecs.umich.edu$dir1 = "tracediff-$$-1";
1351442Sstever@eecs.umich.edu$dir2 = "tracediff-$$-2";
1361442Sstever@eecs.umich.edumkdir($dir1) or die "Can't create dir $dir1\n";
1371442Sstever@eecs.umich.edumkdir($dir2) or die "Can't create dir $dir2\n";
1381123Sstever@eecs.umich.edu
1393362Sstever@eecs.umich.edu$cmd1 = "$sim1 -d $dir1 $args1 2>&1 |";
1403362Sstever@eecs.umich.edu$cmd2 = "$sim2 -d $dir2 $args2 2>&1 |";
141247Sstever@eecs.umich.edu
1424018Sstever@eecs.umich.edu# Expect that rundiff is in the same dir as the tracediff script.
1434018Sstever@eecs.umich.edu# FindBin figures that out for us.
1444018Sstever@eecs.umich.edu$fullcmd = "$FindBin::Bin/rundiff '$cmd1' '$cmd2' 2>&1 > tracediff-$$.out";
145247Sstever@eecs.umich.edu
146247Sstever@eecs.umich.eduprint "Executing $fullcmd\n";
147247Sstever@eecs.umich.edusystem($fullcmd);
148247Sstever@eecs.umich.edu
149247Sstever@eecs.umich.edu
150247Sstever@eecs.umich.edu
151