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 = ''; 905751SSteve.Reinhardt@amd.com @subargs = split('#', $arg); 915725SSteve.Reinhardt@amd.com foreach $subarg (@subargs) { 925751SSteve.Reinhardt@amd.com if ($subarg eq '') { 935751SSteve.Reinhardt@amd.com next; 945751SSteve.Reinhardt@amd.com } 955725SSteve.Reinhardt@amd.com @pair = split('\|', $subarg, -1); # -1 enables null trailing fields 965725SSteve.Reinhardt@amd.com if (@pair == 1) { 975725SSteve.Reinhardt@amd.com $a1 .= $subarg; 985725SSteve.Reinhardt@amd.com $a2 .= $subarg; 995725SSteve.Reinhardt@amd.com } elsif (@pair == 2) { 1005725SSteve.Reinhardt@amd.com $a1 .= $pair[0]; 1015725SSteve.Reinhardt@amd.com $a2 .= $pair[1]; 1025725SSteve.Reinhardt@amd.com } else { 1035751SSteve.Reinhardt@amd.com print 'Parse error: too many |s in ', $arg, "\n"; 1045725SSteve.Reinhardt@amd.com exit(1); 1055725SSteve.Reinhardt@amd.com } 1063362Sstever@eecs.umich.edu } 1075725SSteve.Reinhardt@amd.com 1085725SSteve.Reinhardt@amd.com push @cmd1, $a1; 1095725SSteve.Reinhardt@amd.com push @cmd2, $a2; 1105725SSteve.Reinhardt@amd.com} 1115725SSteve.Reinhardt@amd.com 1125725SSteve.Reinhardt@amd.com 1135725SSteve.Reinhardt@amd.comif ($dryrun) { 1145725SSteve.Reinhardt@amd.com print "CMD1: ", join(' ', @cmd1), "\n"; 1155725SSteve.Reinhardt@amd.com print "CMD2: ", join(' ', @cmd2), "\n"; 1165725SSteve.Reinhardt@amd.com exit(0); 117247Sstever@eecs.umich.edu} 118247Sstever@eecs.umich.edu 119247Sstever@eecs.umich.edu# First two args are the two simulator binaries to compare 1203362Sstever@eecs.umich.edu$sim1 = shift @cmd1; 1213362Sstever@eecs.umich.edu$sim2 = shift @cmd2; 122247Sstever@eecs.umich.edu 1233362Sstever@eecs.umich.edu# Everything else is a simulator arg. 1243362Sstever@eecs.umich.edu$args1 = join(' ', @cmd1); 1253362Sstever@eecs.umich.edu$args2 = join(' ', @cmd2); 126247Sstever@eecs.umich.edu 1278445Sgblack@eecs.umich.edu# Common mistake: if you don't set any debugflags this often isn't 1283370Sstever@eecs.umich.edu# doing what you want. 1298445Sgblack@eecs.umich.eduif ($args1 !~ /--debug-flags/) { 1303370Sstever@eecs.umich.edu print "****\n"; 1318445Sgblack@eecs.umich.edu print "**** WARNING: no debug flags set... you may not be diffing much!\n"; 1323370Sstever@eecs.umich.edu print "****\n"; 1333370Sstever@eecs.umich.edu} 1343370Sstever@eecs.umich.edu 1351442Sstever@eecs.umich.edu# Run individual invocations in separate dirs so output and intermediate 1361442Sstever@eecs.umich.edu# files (particularly config.py and config.ini) don't conflict. 1371442Sstever@eecs.umich.edu$dir1 = "tracediff-$$-1"; 1381442Sstever@eecs.umich.edu$dir2 = "tracediff-$$-2"; 1391442Sstever@eecs.umich.edumkdir($dir1) or die "Can't create dir $dir1\n"; 1401442Sstever@eecs.umich.edumkdir($dir2) or die "Can't create dir $dir2\n"; 1411123Sstever@eecs.umich.edu 1423362Sstever@eecs.umich.edu$cmd1 = "$sim1 -d $dir1 $args1 2>&1 |"; 1433362Sstever@eecs.umich.edu$cmd2 = "$sim2 -d $dir2 $args2 2>&1 |"; 144247Sstever@eecs.umich.edu 1454018Sstever@eecs.umich.edu# Expect that rundiff is in the same dir as the tracediff script. 1464018Sstever@eecs.umich.edu# FindBin figures that out for us. 1474018Sstever@eecs.umich.edu$fullcmd = "$FindBin::Bin/rundiff '$cmd1' '$cmd2' 2>&1 > tracediff-$$.out"; 148247Sstever@eecs.umich.edu 149247Sstever@eecs.umich.eduprint "Executing $fullcmd\n"; 150247Sstever@eecs.umich.edusystem($fullcmd); 151247Sstever@eecs.umich.edu 152247Sstever@eecs.umich.edu 153247Sstever@eecs.umich.edu 154