tracediff revision 4018
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 311123Sstever@eecs.umich.edu# invocations of m5. 321123Sstever@eecs.umich.edu# 331746Shsul@eecs.umich.edu# ******Note that you need to enable some trace flags in the args in order 341746Shsul@eecs.umich.edu# to do anything useful!****** 351123Sstever@eecs.umich.edu# 363362Sstever@eecs.umich.edu# Script arguments are handled uniformly as follows: 373362Sstever@eecs.umich.edu# - If the argument does not contain a '|' character, it is appended 383362Sstever@eecs.umich.edu# to both command lines. 393362Sstever@eecs.umich.edu# - If the argument has a '|' character in it, the text on either side 403362Sstever@eecs.umich.edu# of the '|' is appended to the respective command lines. Note that 413362Sstever@eecs.umich.edu# you'll have to quote the arg or escape the '|' with a backslash 423362Sstever@eecs.umich.edu# so that the shell doesn't think you're doing a pipe. 431123Sstever@eecs.umich.edu# 443370Sstever@eecs.umich.edu# In other words, the arguments should look like the command line you 453370Sstever@eecs.umich.edu# want to run, with "|" used to list the alternatives for the parts 463370Sstever@eecs.umich.edu# that you want to differ between the two runs. 473370Sstever@eecs.umich.edu# 483362Sstever@eecs.umich.edu# For example: 493362Sstever@eecs.umich.edu# 503362Sstever@eecs.umich.edu# % tracediff m5.opt --opt1 "--opt2|--opt3" --opt4 513362Sstever@eecs.umich.edu# would compare these two runs: 523362Sstever@eecs.umich.edu# m5.opt --opt1 --opt2 --opt4 533362Sstever@eecs.umich.edu# m5.opt --opt1 --opt3 --opt4 543362Sstever@eecs.umich.edu# 553362Sstever@eecs.umich.edu# If you want to compare two different simulator binaries, put a '|' 563362Sstever@eecs.umich.edu# in the first script argument ("path1/m5.opt|path2/m5.opt"). If you 573362Sstever@eecs.umich.edu# want to add arguments to one run only, just put a '|' in with text 583362Sstever@eecs.umich.edu# only on one side ("--onlyOn1|"). You can do this with multiple 593362Sstever@eecs.umich.edu# arguments together too ("|-a -b -c" adds three args to the second 603362Sstever@eecs.umich.edu# run only). 611123Sstever@eecs.umich.edu# 62247Sstever@eecs.umich.edu 634018Sstever@eecs.umich.eduuse FindBin; 644018Sstever@eecs.umich.edu 65247Sstever@eecs.umich.eduif (@ARGV < 2) { 663362Sstever@eecs.umich.edu die "Usage: tracediff \"sim1|sim2\" [common-arg \"arg1|arg2\" ...]\n"; 673362Sstever@eecs.umich.edu} 683362Sstever@eecs.umich.edu 693362Sstever@eecs.umich.eduforeach $arg (@ARGV) { 703362Sstever@eecs.umich.edu @pair = split('\|', $arg, -1); # -1 enables null trailing fields 713362Sstever@eecs.umich.edu if ($#pair > 0) { 723362Sstever@eecs.umich.edu push @cmd1, $pair[0]; 733362Sstever@eecs.umich.edu push @cmd2, $pair[1]; 743362Sstever@eecs.umich.edu } else { 753362Sstever@eecs.umich.edu push @cmd1, $arg; 763362Sstever@eecs.umich.edu push @cmd2, $arg; 773362Sstever@eecs.umich.edu } 78247Sstever@eecs.umich.edu} 79247Sstever@eecs.umich.edu 80247Sstever@eecs.umich.edu# First two args are the two simulator binaries to compare 813362Sstever@eecs.umich.edu$sim1 = shift @cmd1; 823362Sstever@eecs.umich.edu$sim2 = shift @cmd2; 83247Sstever@eecs.umich.edu 843362Sstever@eecs.umich.edu# Everything else is a simulator arg. 853362Sstever@eecs.umich.edu$args1 = join(' ', @cmd1); 863362Sstever@eecs.umich.edu$args2 = join(' ', @cmd2); 87247Sstever@eecs.umich.edu 883370Sstever@eecs.umich.edu# Common mistake: if you don't set any traceflags this often isn't 893370Sstever@eecs.umich.edu# doing what you want. 903370Sstever@eecs.umich.eduif ($args1 !~ /--trace-flags/) { 913370Sstever@eecs.umich.edu print "****\n"; 923370Sstever@eecs.umich.edu print "**** WARNING: no trace flags set... you may not be diffing much!\n"; 933370Sstever@eecs.umich.edu print "****\n"; 943370Sstever@eecs.umich.edu} 953370Sstever@eecs.umich.edu 961442Sstever@eecs.umich.edu# Run individual invocations in separate dirs so output and intermediate 971442Sstever@eecs.umich.edu# files (particularly config.py and config.ini) don't conflict. 981442Sstever@eecs.umich.edu$dir1 = "tracediff-$$-1"; 991442Sstever@eecs.umich.edu$dir2 = "tracediff-$$-2"; 1001442Sstever@eecs.umich.edumkdir($dir1) or die "Can't create dir $dir1\n"; 1011442Sstever@eecs.umich.edumkdir($dir2) or die "Can't create dir $dir2\n"; 1021123Sstever@eecs.umich.edu 1033362Sstever@eecs.umich.edu$cmd1 = "$sim1 -d $dir1 $args1 2>&1 |"; 1043362Sstever@eecs.umich.edu$cmd2 = "$sim2 -d $dir2 $args2 2>&1 |"; 105247Sstever@eecs.umich.edu 1064018Sstever@eecs.umich.edu# Expect that rundiff is in the same dir as the tracediff script. 1074018Sstever@eecs.umich.edu# FindBin figures that out for us. 1084018Sstever@eecs.umich.edu$fullcmd = "$FindBin::Bin/rundiff '$cmd1' '$cmd2' 2>&1 > tracediff-$$.out"; 109247Sstever@eecs.umich.edu 110247Sstever@eecs.umich.eduprint "Executing $fullcmd\n"; 111247Sstever@eecs.umich.edusystem($fullcmd); 112247Sstever@eecs.umich.edu 113247Sstever@eecs.umich.edu 114247Sstever@eecs.umich.edu 115