tracediff revision 5751
1247Sstever@eecs.umich.edu#! /usr/bin/env perl 21372Sstever@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 311123Sstever@eecs.umich.edu# invocations of m5. Takes a common m5 command line with embedded 321123Sstever@eecs.umich.edu# alternatives and executes the two alternative commands in separate 331746Shsul@eecs.umich.edu# subdirectories with output piped to rundiff. 341746Shsul@eecs.umich.edu# 351123Sstever@eecs.umich.edu# ******Note that you need to enable some trace flags in the args in order 361123Sstever@eecs.umich.edu# to do anything useful!****** 371123Sstever@eecs.umich.edu# 381123Sstever@eecs.umich.edu# Script arguments are handled uniformly as follows: 391746Shsul@eecs.umich.edu# - If the argument does not contain a '|' character, it is appended 401123Sstever@eecs.umich.edu# to both command lines. 41247Sstever@eecs.umich.edu# - If the argument has a '|' character in it, the text on either side 42247Sstever@eecs.umich.edu# of the '|' is appended to the respective command lines. Note that 431746Shsul@eecs.umich.edu# you'll have to quote the arg or escape the '|' with a backslash 44247Sstever@eecs.umich.edu# so that the shell doesn't think you're doing a pipe. 45247Sstever@eecs.umich.edu# - Arguments with '#' characters are split at those characters, 46247Sstever@eecs.umich.edu# processed for alternatives ('|'s) as independent terms, then 47247Sstever@eecs.umich.edu# pasted back into a single argument (without the '#'s). (Sort of 48247Sstever@eecs.umich.edu# inspired by the C preprocessor '##' token pasting operator.) 49247Sstever@eecs.umich.edu# 50247Sstever@eecs.umich.edu# In other words, the arguments should look like the command line you 51247Sstever@eecs.umich.edu# want to run, with "|" used to list the alternatives for the parts 52579Sstever@eecs.umich.edu# that you want to differ between the two runs. 53247Sstever@eecs.umich.edu# 541442Sstever@eecs.umich.edu# For example: 551442Sstever@eecs.umich.edu# 561442Sstever@eecs.umich.edu# % tracediff m5.opt --opt1 '--opt2|--opt3' --opt4 571442Sstever@eecs.umich.edu# would compare these two runs: 581442Sstever@eecs.umich.edu# m5.opt --opt1 --opt2 --opt4 591442Sstever@eecs.umich.edu# m5.opt --opt1 --opt3 --opt4 601123Sstever@eecs.umich.edu# 611442Sstever@eecs.umich.edu# % tracediff 'path1|path2#/m5.opt' --opt1 --opt2 621442Sstever@eecs.umich.edu# would compare these two runs: 63247Sstever@eecs.umich.edu# path1/m5.opt --opt1 --opt2 64247Sstever@eecs.umich.edu# path2/m5.opt --opt1 --opt2 65247Sstever@eecs.umich.edu# 66247Sstever@eecs.umich.edu# If you want to add arguments to one run only, just put a '|' in with 67247Sstever@eecs.umich.edu# text only on one side ('--onlyOn1|'). You can do this with multiple 68247Sstever@eecs.umich.edu# arguments together too ('|-a -b -c' adds three args to the second 69247Sstever@eecs.umich.edu# run only). 70247Sstever@eecs.umich.edu# 71247Sstever@eecs.umich.edu# The '-n' argument to tracediff allows you to preview the two 72247Sstever@eecs.umich.edu# generated command lines without running them. 73# 74 75use FindBin; 76 77$dryrun = 0; 78 79if (@ARGV >= 1 && $ARGV[0] eq '-n') { 80 $dryrun = 1; 81 shift @ARGV; 82} 83 84if (@ARGV < 1) { 85 die "Usage: tracediff [-n] \"sim1|sim2\" [common-arg \"arg1|arg2\" ...]\n"; 86} 87 88foreach $arg (@ARGV) { 89 $a1 = $a2 = ''; 90 @subargs = split('#', $arg); 91 foreach $subarg (@subargs) { 92 if ($subarg eq '') { 93 next; 94 } 95 @pair = split('\|', $subarg, -1); # -1 enables null trailing fields 96 if (@pair == 1) { 97 $a1 .= $subarg; 98 $a2 .= $subarg; 99 } elsif (@pair == 2) { 100 $a1 .= $pair[0]; 101 $a2 .= $pair[1]; 102 } else { 103 print 'Parse error: too many |s in ', $arg, "\n"; 104 exit(1); 105 } 106 } 107 108 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