2 # Script to find regressions by binary-searching a time interval in the
3 # CVS tree. Written by Brian Gaeke on 2-Mar-2004.
6 require 5.6.0; # NOTE: This script not tested with earlier versions.
14 findRegression [-I] -w WTIME -d DTIME -t TOOLS -c SCRIPT
16 The -w, -d, -t, and -c options are required.
17 Run findRegression in the top level of an LLVM tree.
18 WTIME is a time when you are sure the regression does NOT exist ("Works").
19 DTIME is a time when you are sure the regression DOES exist ("Doesntwork").
20 WTIME and DTIME are both in the format: "YYYY/MM/DD HH:MM".
21 -I means run builds at WTIME and DTIME first to make sure.
22 TOOLS is a comma separated list of tools to rebuild before running SCRIPT.
23 SCRIPT exits 1 if the regression is present in TOOLS; 0 otherwise.
31 if ( $timestr =~ /(\d\d\d\d)\/(\d\d)\/(\d\d) (\d\d):(\d\d)/ ) {
32 my ( $year, $mon, $mday, $hour, $min ) = ( $1, $2, $3, $4, $5 );
33 return timegm( 0, $min, $hour, $mday, $mon - 1, $year );
36 die "** Can't parse date + time: $timestr\n";
42 return strftime( "%Y/%m/%d %H:%M", gmtime($secs) );
47 print LOG "** Running: $cmdline\n";
48 return system($cmdline);
51 sub buildLibrariesAndTools {
52 run("sh /home/vadve/gaeke/scripts/run-configure");
53 run("$MAKE -C lib/Support");
54 run("$MAKE -C utils");
56 foreach my $tool (@TOOLS) { run("$MAKE -C tools/$tool"); }
60 my ( $file, $regex ) = @_;
62 open( FILE, "<$file" ) or die "** can't read $file: $!\n";
75 my $inst = "include/llvm/Instruction.h";
77 run( "cvs update -D'" . timeAsString($time) . "'" );
78 if ( !contains( $inst, 'class Instruction.*Annotable' ) ) {
79 run("patch -F100 -p0 < makeInstructionAnnotable.patch");
83 sub regressionPresentAt {
87 buildLibrariesAndTools();
88 my $rc = run($SCRIPT);
90 print LOG "** Found that regression was PRESENT at "
91 . timeAsString($time) . "\n";
95 print LOG "** Found that regression was ABSENT at "
96 . timeAsString($time) . "\n";
101 sub regressionAbsentAt {
103 return !regressionPresentAt($time);
107 my ( $time1, $time2 ) = @_;
108 return abs( $time1 - $time2 ) < 600; # 10 minutes seems reasonable.
112 my ( $time1, $time2 ) = @_;
113 my $halfSpan = int( abs( $time1 - $time2 ) / 2 );
114 if ( $time1 < $time2 ) {
115 return $time1 + $halfSpan;
118 return $time2 + $halfSpan;
122 sub checkBoundaryConditions {
123 print LOG "** Checking for presence of regression at ", timeAsString($DTIME),
125 if ( !regressionPresentAt($DTIME) ) {
126 die ( "** Can't help you; $SCRIPT says regression absent at dtime: "
127 . timeAsString($DTIME)
130 print LOG "** Checking for absence of regression at ", timeAsString($WTIME),
132 if ( !regressionAbsentAt($WTIME) ) {
133 die ( "** Can't help you; $SCRIPT says regression present at wtime: "
134 . timeAsString($WTIME)
139 ##############################################################################
142 open (STDERR, ">&STDOUT") || die "** Can't redirect std.err: $!\n";
145 open (LOG, ">RegFinder.log") || die "** can't write RegFinder.log: $!\n";
147 # Check command line arguments and environment variables
148 getopts('Iw:d:t:c:');
149 if ( !( $opt_w && $opt_d && $opt_t && $opt_c ) ) {
152 $MAKE = $ENV{'MAKE'};
153 $MAKE = 'gmake' unless $MAKE;
154 $WTIME = timeAsSeconds($opt_w);
155 print LOG "** Assuming worked at ", timeAsString($WTIME), "\n";
156 $DTIME = timeAsSeconds($opt_d);
157 print LOG "** Assuming didn't work at ", timeAsString($DTIME), "\n";
160 die "** $SCRIPT is not executable or not found\n" unless -x $SCRIPT;
161 print LOG "** Checking for the regression using $SCRIPT\n";
162 @TOOLS = split ( /,/, $opt_t );
164 "** Going to rebuild: ",
165 ( join ", ", @TOOLS ),
166 " before each $SCRIPT run\n"
168 if ($opt_I) { checkBoundaryConditions(); }
170 while ( !closeTo( $DTIME, $WTIME ) ) {
171 my $halfPt = halfWayPoint( $DTIME, $WTIME );
172 print LOG "** Checking whether regression is present at ",
173 timeAsString($halfPt), "\n";
174 if ( regressionPresentAt($halfPt) ) {
181 # Tell them what we found
182 print LOG "** Narrowed it down to:\n";
183 print LOG "** Worked at: ", timeAsString($WTIME), "\n";
184 print LOG "** Did not work at: ", timeAsString($DTIME), "\n";