tracediff revision 5751:54cb03a1a577
17404SAli.Saidi@ARM.com#! /usr/bin/env perl 212709Sgiacomo.travaglini@arm.com# Copyright (c) 2003-2007 The Regents of The University of Michigan 37404SAli.Saidi@ARM.com# All rights reserved. 47404SAli.Saidi@ARM.com# 57404SAli.Saidi@ARM.com# Redistribution and use in source and binary forms, with or without 67404SAli.Saidi@ARM.com# modification, are permitted provided that the following conditions are 77404SAli.Saidi@ARM.com# met: redistributions of source code must retain the above copyright 87404SAli.Saidi@ARM.com# notice, this list of conditions and the following disclaimer; 97404SAli.Saidi@ARM.com# redistributions in binary form must reproduce the above copyright 107404SAli.Saidi@ARM.com# notice, this list of conditions and the following disclaimer in the 117404SAli.Saidi@ARM.com# documentation and/or other materials provided with the distribution; 127404SAli.Saidi@ARM.com# neither the name of the copyright holders nor the names of its 137404SAli.Saidi@ARM.com# contributors may be used to endorse or promote products derived from 147404SAli.Saidi@ARM.com# this software without specific prior written permission. 157404SAli.Saidi@ARM.com# 167404SAli.Saidi@ARM.com# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 177404SAli.Saidi@ARM.com# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 187404SAli.Saidi@ARM.com# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 197404SAli.Saidi@ARM.com# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 207404SAli.Saidi@ARM.com# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 217404SAli.Saidi@ARM.com# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 227404SAli.Saidi@ARM.com# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 237404SAli.Saidi@ARM.com# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 247404SAli.Saidi@ARM.com# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 257404SAli.Saidi@ARM.com# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 267404SAli.Saidi@ARM.com# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 277404SAli.Saidi@ARM.com# 287404SAli.Saidi@ARM.com# Authors: Steve Reinhardt 297404SAli.Saidi@ARM.com 307404SAli.Saidi@ARM.com# Script to simplify using rundiff on trace outputs from two 317404SAli.Saidi@ARM.com# invocations of m5. Takes a common m5 command line with embedded 327404SAli.Saidi@ARM.com# alternatives and executes the two alternative commands in separate 337404SAli.Saidi@ARM.com# subdirectories with output piped to rundiff. 347404SAli.Saidi@ARM.com# 357404SAli.Saidi@ARM.com# ******Note that you need to enable some trace flags in the args in order 367404SAli.Saidi@ARM.com# to do anything useful!****** 377404SAli.Saidi@ARM.com# 3810037SARM gem5 Developers# Script arguments are handled uniformly as follows: 397404SAli.Saidi@ARM.com# - If the argument does not contain a '|' character, it is appended 4010873Sandreas.sandberg@arm.com# to both command lines. 417404SAli.Saidi@ARM.com# - If the argument has a '|' character in it, the text on either side 4210474Sandreas.hansson@arm.com# of the '|' is appended to the respective command lines. Note that 4310474Sandreas.hansson@arm.com# you'll have to quote the arg or escape the '|' with a backslash 447404SAli.Saidi@ARM.com# so that the shell doesn't think you're doing a pipe. 4510037SARM gem5 Developers# - Arguments with '#' characters are split at those characters, 4610037SARM gem5 Developers# processed for alternatives ('|'s) as independent terms, then 477404SAli.Saidi@ARM.com# pasted back into a single argument (without the '#'s). (Sort of 487728SAli.Saidi@ARM.com# inspired by the C preprocessor '##' token pasting operator.) 497404SAli.Saidi@ARM.com# 508245Snate@binkert.org# In other words, the arguments should look like the command line you 519152Satgutier@umich.edu# want to run, with "|" used to list the alternatives for the parts 528245Snate@binkert.org# that you want to differ between the two runs. 538245Snate@binkert.org# 5410873Sandreas.sandberg@arm.com# For example: 557748SAli.Saidi@ARM.com# 567404SAli.Saidi@ARM.com# % tracediff m5.opt --opt1 '--opt2|--opt3' --opt4 577404SAli.Saidi@ARM.com# would compare these two runs: 587404SAli.Saidi@ARM.com# m5.opt --opt1 --opt2 --opt4 597404SAli.Saidi@ARM.com# m5.opt --opt1 --opt3 --opt4 6010913Sandreas.sandberg@arm.com# 6110717Sandreas.hansson@arm.com# % tracediff 'path1|path2#/m5.opt' --opt1 --opt2 6210717Sandreas.hansson@arm.com# would compare these two runs: 6310717Sandreas.hansson@arm.com# path1/m5.opt --opt1 --opt2 649258SAli.Saidi@ARM.com# path2/m5.opt --opt1 --opt2 6510621SCurtis.Dunham@arm.com# 6610621SCurtis.Dunham@arm.com# If you want to add arguments to one run only, just put a '|' in with 6712086Sspwilson2@wisc.edu# text only on one side ('--onlyOn1|'). You can do this with multiple 6812086Sspwilson2@wisc.edu# arguments together too ('|-a -b -c' adds three args to the second 6912086Sspwilson2@wisc.edu# run only). 7012086Sspwilson2@wisc.edu# 7112086Sspwilson2@wisc.edu# The '-n' argument to tracediff allows you to preview the two 7212086Sspwilson2@wisc.edu# generated command lines without running them. 7311588SCurtis.Dunham@arm.com# 7411588SCurtis.Dunham@arm.com 7512086Sspwilson2@wisc.eduuse FindBin; 767439Sdam.sunwoo@arm.com 777576SAli.Saidi@ARM.com$dryrun = 0; 7810037SARM gem5 Developers 7910037SARM gem5 Developersif (@ARGV >= 1 && $ARGV[0] eq '-n') { 8010037SARM gem5 Developers $dryrun = 1; 8110717Sandreas.hansson@arm.com shift @ARGV; 8210037SARM gem5 Developers} 8310037SARM gem5 Developers 8410037SARM gem5 Developersif (@ARGV < 1) { 8510037SARM gem5 Developers die "Usage: tracediff [-n] \"sim1|sim2\" [common-arg \"arg1|arg2\" ...]\n"; 8610037SARM gem5 Developers} 8710037SARM gem5 Developers 8810037SARM gem5 Developersforeach $arg (@ARGV) { 8910037SARM gem5 Developers $a1 = $a2 = ''; 9010037SARM gem5 Developers @subargs = split('#', $arg); 9110037SARM gem5 Developers foreach $subarg (@subargs) { 9210037SARM gem5 Developers if ($subarg eq '') { 9310037SARM gem5 Developers next; 947439Sdam.sunwoo@arm.com } 957404SAli.Saidi@ARM.com @pair = split('\|', $subarg, -1); # -1 enables null trailing fields 967404SAli.Saidi@ARM.com if (@pair == 1) { 977404SAli.Saidi@ARM.com $a1 .= $subarg; 987404SAli.Saidi@ARM.com $a2 .= $subarg; 997404SAli.Saidi@ARM.com } elsif (@pair == 2) { 1007404SAli.Saidi@ARM.com $a1 .= $pair[0]; 10110717Sandreas.hansson@arm.com $a2 .= $pair[1]; 10210717Sandreas.hansson@arm.com } else { 10310717Sandreas.hansson@arm.com print 'Parse error: too many |s in ', $arg, "\n"; 10410717Sandreas.hansson@arm.com exit(1); 10510717Sandreas.hansson@arm.com } 10610717Sandreas.hansson@arm.com } 10710717Sandreas.hansson@arm.com 10810717Sandreas.hansson@arm.com push @cmd1, $a1; 10910717Sandreas.hansson@arm.com push @cmd2, $a2; 11010717Sandreas.hansson@arm.com} 11110717Sandreas.hansson@arm.com 11210717Sandreas.hansson@arm.com 11310717Sandreas.hansson@arm.comif ($dryrun) { 11410717Sandreas.hansson@arm.com print "CMD1: ", join(' ', @cmd1), "\n"; 11510717Sandreas.hansson@arm.com print "CMD2: ", join(' ', @cmd2), "\n"; 11610717Sandreas.hansson@arm.com exit(0); 11710717Sandreas.hansson@arm.com} 11810717Sandreas.hansson@arm.com 11910717Sandreas.hansson@arm.com# First two args are the two simulator binaries to compare 12010717Sandreas.hansson@arm.com$sim1 = shift @cmd1; 12110717Sandreas.hansson@arm.com$sim2 = shift @cmd2; 12210717Sandreas.hansson@arm.com 12310717Sandreas.hansson@arm.com# Everything else is a simulator arg. 12410717Sandreas.hansson@arm.com$args1 = join(' ', @cmd1); 12510717Sandreas.hansson@arm.com$args2 = join(' ', @cmd2); 12610717Sandreas.hansson@arm.com 12710717Sandreas.hansson@arm.com# Common mistake: if you don't set any traceflags this often isn't 12810717Sandreas.hansson@arm.com# doing what you want. 12910717Sandreas.hansson@arm.comif ($args1 !~ /--trace-flags/) { 13010537Sandreas.hansson@arm.com print "****\n"; 13110537Sandreas.hansson@arm.com print "**** WARNING: no trace flags set... you may not be diffing much!\n"; 13210537Sandreas.hansson@arm.com print "****\n"; 13310537Sandreas.hansson@arm.com} 13410537Sandreas.hansson@arm.com 13512738Sandreas.sandberg@arm.com# Run individual invocations in separate dirs so output and intermediate 13610537Sandreas.hansson@arm.com# files (particularly config.py and config.ini) don't conflict. 13710537Sandreas.hansson@arm.com$dir1 = "tracediff-$$-1"; 13810537Sandreas.hansson@arm.com$dir2 = "tracediff-$$-2"; 13910037SARM gem5 Developersmkdir($dir1) or die "Can't create dir $dir1\n"; 14010037SARM gem5 Developersmkdir($dir2) or die "Can't create dir $dir2\n"; 14110037SARM gem5 Developers 1429152Satgutier@umich.edu$cmd1 = "$sim1 -d $dir1 $args1 2>&1 |"; 1439152Satgutier@umich.edu$cmd2 = "$sim2 -d $dir2 $args2 2>&1 |"; 1449152Satgutier@umich.edu 14510913Sandreas.sandberg@arm.com# Expect that rundiff is in the same dir as the tracediff script. 14611588SCurtis.Dunham@arm.com# FindBin figures that out for us. 14711588SCurtis.Dunham@arm.com$fullcmd = "$FindBin::Bin/rundiff '$cmd1' '$cmd2' 2>&1 > tracediff-$$.out"; 1489152Satgutier@umich.edu 14910913Sandreas.sandberg@arm.comprint "Executing $fullcmd\n"; 1509152Satgutier@umich.edusystem($fullcmd); 15110913Sandreas.sandberg@arm.com 1529152Satgutier@umich.edu 1539152Satgutier@umich.edu 1549152Satgutier@umich.edu