1 #! /usr/dcs/software/supported/bin/perl
2 # Script to find regressions by binary-searching a time interval in the CVS tree.
3 # Written by Brian Gaeke on 2-Mar-2004
13 findRegression [-I] -w WTIME -d DTIME -t TOOLS -c SCRIPT
15 The -w, -d, -t, and -c options are required.
16 Run findRegression in the top level of an LLVM tree.
17 WTIME is a time when you are sure the regression does NOT exist ("Works").
18 DTIME is a time when you are sure the regression DOES exist ("Doesntwork").
19 WTIME and DTIME are both in the format: "YYYY/MM/DD HH:MM".
20 -I means run builds at WTIME and DTIME first to make sure.
21 TOOLS is a comma separated list of tools to rebuild before running SCRIPT.
22 SCRIPT exits 1 if the regression is present in TOOLS; 0 otherwise.
30 if ( $timestr =~ /(\d\d\d\d)\/(\d\d)\/(\d\d) (\d\d):(\d\d)/ ) {
31 my ( $year, $mon, $mday, $hour, $min ) = ( $1, $2, $3, $4, $5 );
32 return timegm( 0, $min, $hour, $mday, $mon - 1, $year );
35 die "** Can't parse date + time: $timestr\n";
41 return strftime( "%Y/%m/%d %H:%M", gmtime($secs) );
46 print LOG "** Running: $cmdline\n";
47 return system($cmdline);
50 sub buildLibrariesAndTools {
51 run("sh /home/vadve/gaeke/scripts/run-configure");
52 run("$MAKE -C lib/Support");
53 run("$MAKE -C utils");
55 foreach my $tool (@TOOLS) { run("$MAKE -C tools/$tool"); }
59 my ( $file, $regex ) = @_;
61 open( FILE, "<$file" ) or die "** can't read $file: $!\n";
74 my $inst = "include/llvm/Instruction.h";
76 run( "cvs update -D'" . timeAsString($time) . "'" );
77 if ( !contains( $inst, 'class Instruction.*Annotable' ) ) {
78 run("patch -F100 -p0 < makeInstructionAnnotable.patch");
82 sub regressionPresentAt {
86 buildLibrariesAndTools();
87 my $rc = run($SCRIPT);
89 print LOG "** Found that regression was PRESENT at "
90 . timeAsString($time) . "\n";
94 print LOG "** Found that regression was ABSENT at "
95 . timeAsString($time) . "\n";
100 sub regressionAbsentAt {
102 return !regressionPresentAt($time);
106 my ( $time1, $time2 ) = @_;
107 return abs( $time1 - $time2 ) < 600; # 10 minutes seems reasonable.
111 my ( $time1, $time2 ) = @_;
112 my $halfSpan = int( abs( $time1 - $time2 ) / 2 );
113 if ( $time1 < $time2 ) {
114 return $time1 + $halfSpan;
117 return $time2 + $halfSpan;
121 sub checkBoundaryConditions {
122 print LOG "** Checking for presence of regression at ", timeAsString($DTIME),
124 if ( !regressionPresentAt($DTIME) ) {
125 die ( "** Can't help you; $SCRIPT says regression absent at dtime: "
126 . timeAsString($DTIME)
129 print LOG "** Checking for absence of regression at ", timeAsString($WTIME),
131 if ( !regressionAbsentAt($WTIME) ) {
132 die ( "** Can't help you; $SCRIPT says regression present at wtime: "
133 . timeAsString($WTIME)
138 ##############################################################################
141 open (STDERR, ">&STDOUT") || die "** Can't redirect std.err: $!\n";
144 open (LOG, ">RegFinder.log") || die "** can't write RegFinder.log: $!\n";
146 # Check command line arguments and environment variables
147 getopts('Iw:d:t:c:');
148 if ( !( $opt_w && $opt_d && $opt_t && $opt_c ) ) {
151 $MAKE = $ENV{'MAKE'};
152 $MAKE = 'gmake' unless $MAKE;
153 $WTIME = timeAsSeconds($opt_w);
154 print LOG "** Assuming worked at ", timeAsString($WTIME), "\n";
155 $DTIME = timeAsSeconds($opt_d);
156 print LOG "** Assuming didn't work at ", timeAsString($DTIME), "\n";
159 die "** $SCRIPT is not executable or not found\n" unless -x $SCRIPT;
160 print LOG "** Checking for the regression using $SCRIPT\n";
161 @TOOLS = split ( /,/, $opt_t );
163 "** Going to rebuild: ",
164 ( join ", ", @TOOLS ),
165 " before each $SCRIPT run\n"
167 if ($opt_I) { checkBoundaryConditions(); }
169 while ( !closeTo( $DTIME, $WTIME ) ) {
170 my $halfPt = halfWayPoint( $DTIME, $WTIME );
171 print LOG "** Checking whether regression is present at ",
172 timeAsString($halfPt), "\n";
173 if ( regressionPresentAt($halfPt) ) {
180 # Tell them what we found
181 print LOG "** Narrowed it down to:\n";
182 print LOG "** Worked at: ", timeAsString($WTIME), "\n";
183 print LOG "** Did not work at: ", timeAsString($DTIME), "\n";