tracediff revision 5751
16157Snate@binkert.org#! /usr/bin/env perl 26157Snate@binkert.org# Copyright (c) 2003-2007 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. Takes a common m5 command line with embedded 326157Snate@binkert.org# alternatives and executes the two alternative commands in separate 336157Snate@binkert.org# subdirectories with output piped to rundiff. 346157Snate@binkert.org# 356157Snate@binkert.org# ******Note that you need to enable some trace flags in the args in order 366157Snate@binkert.org# to do anything useful!****** 376157Snate@binkert.org# 386157Snate@binkert.org# Script arguments are handled uniformly as follows: 396157Snate@binkert.org# - If the argument does not contain a '|' character, it is appended 407768SAli.Saidi@ARM.com# to both command lines. 417768SAli.Saidi@ARM.com# - If the argument has a '|' character in it, the text on either side 427768SAli.Saidi@ARM.com# of the '|' is appended to the respective command lines. Note that 436168Snate@binkert.org# you'll have to quote the arg or escape the '|' with a backslash 446168Snate@binkert.org# so that the shell doesn't think you're doing a pipe. 456168Snate@binkert.org# - Arguments with '#' characters are split at those characters, 466157Snate@binkert.org# processed for alternatives ('|'s) as independent terms, then 476157Snate@binkert.org# pasted back into a single argument (without the '#'s). (Sort of 486157Snate@binkert.org# inspired by the C preprocessor '##' token pasting operator.) 496157Snate@binkert.org# 506157Snate@binkert.org# In other words, the arguments should look like the command line you 516157Snate@binkert.org# want to run, with "|" used to list the alternatives for the parts 526157Snate@binkert.org# that you want to differ between the two runs. 536157Snate@binkert.org# 546157Snate@binkert.org# For example: 556157Snate@binkert.org# 566157Snate@binkert.org# % tracediff m5.opt --opt1 '--opt2|--opt3' --opt4 576157Snate@binkert.org# would compare these two runs: 586157Snate@binkert.org# m5.opt --opt1 --opt2 --opt4 596157Snate@binkert.org# m5.opt --opt1 --opt3 --opt4 606157Snate@binkert.org# 616157Snate@binkert.org# % tracediff 'path1|path2#/m5.opt' --opt1 --opt2 626157Snate@binkert.org# would compare these two runs: 636157Snate@binkert.org# path1/m5.opt --opt1 --opt2 646157Snate@binkert.org# path2/m5.opt --opt1 --opt2 656157Snate@binkert.org# 666157Snate@binkert.org# If you want to add arguments to one run only, just put a '|' in with 676157Snate@binkert.org# text only on one side ('--onlyOn1|'). You can do this with multiple 686157Snate@binkert.org# arguments together too ('|-a -b -c' adds three args to the second 696157Snate@binkert.org# run only). 706157Snate@binkert.org# 716157Snate@binkert.org# The '-n' argument to tracediff allows you to preview the two 726157Snate@binkert.org# generated command lines without running them. 736157Snate@binkert.org# 746157Snate@binkert.org 756157Snate@binkert.orguse FindBin; 766157Snate@binkert.org 776157Snate@binkert.org$dryrun = 0; 786157Snate@binkert.org 796157Snate@binkert.orgif (@ARGV >= 1 && $ARGV[0] eq '-n') { 806157Snate@binkert.org $dryrun = 1; 816157Snate@binkert.org shift @ARGV; 826157Snate@binkert.org} 836157Snate@binkert.org 846157Snate@binkert.orgif (@ARGV < 1) { 856157Snate@binkert.org die "Usage: tracediff [-n] \"sim1|sim2\" [common-arg \"arg1|arg2\" ...]\n"; 866157Snate@binkert.org} 876157Snate@binkert.org 886157Snate@binkert.orgforeach $arg (@ARGV) { 896157Snate@binkert.org $a1 = $a2 = ''; 906157Snate@binkert.org @subargs = split('#', $arg); 916882SBrad.Beckmann@amd.com foreach $subarg (@subargs) { 926286Snate@binkert.org if ($subarg eq '') { 936286Snate@binkert.org next; 946286Snate@binkert.org } 956286Snate@binkert.org @pair = split('\|', $subarg, -1); # -1 enables null trailing fields 968092Snilay@cs.wisc.edu if (@pair == 1) { 976286Snate@binkert.org $a1 .= $subarg; 986286Snate@binkert.org $a2 .= $subarg; 996157Snate@binkert.org } elsif (@pair == 2) { 1006157Snate@binkert.org $a1 .= $pair[0]; 1016157Snate@binkert.org $a2 .= $pair[1]; 1026157Snate@binkert.org } else { 1036157Snate@binkert.org print 'Parse error: too many |s in ', $arg, "\n"; 1046286Snate@binkert.org exit(1); 1056157Snate@binkert.org } 1066286Snate@binkert.org } 1076157Snate@binkert.org 1086157Snate@binkert.org push @cmd1, $a1; 1096157Snate@binkert.org push @cmd2, $a2; 1108191SLisa.Hsu@amd.com} 1116157Snate@binkert.org 1126157Snate@binkert.org 1136797SBrad.Beckmann@amd.comif ($dryrun) { 1146157Snate@binkert.org print "CMD1: ", join(' ', @cmd1), "\n"; 1156157Snate@binkert.org print "CMD2: ", join(' ', @cmd2), "\n"; 1166157Snate@binkert.org 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