diff --git a/scripts/Util.pm b/scripts/Util.pm index f982ae3..495083c 100644 --- a/scripts/Util.pm +++ b/scripts/Util.pm @@ -15,6 +15,8 @@ sub notify { system( 'curl', '-H', "Authorization: Bearer $ntfy_token", '-d', $msg, "$ntfy_url/$ntfy_topic" ); + + sleep(1); } sub notify_file { @@ -25,6 +27,40 @@ sub notify_file { '-T', $file, '-H', "Filename: $file", "$ntfy_url/$ntfy_topic" ); + + sleep(1); +} + +sub rewrite_file { + my ( $file, $matches, $replacement ) = @_; + + open( my $readhandle, '<', $file ) or die "failed to open $file: $!"; + my @lines; + my $found = 0; + while ( my $line = <$readhandle> ) { + if ( index( $line, $matches ) != -1 ) { + $line = $replacement; + $found = 1; + } + push @lines, $line; + } + close($readhandle) or die "failed to close $file: $!"; + + die "no line containing $matches found in $file" unless $found; + + open( my $writehandle, '>', $file ) or die "failed to open $file: $!"; + print $writehandle @lines or die "failed to write $file: $!"; + close($writehandle) or die "failed to close $file: $!"; + + say "Updated $file with $replacement"; +} + +sub cpu_count { + open( my $handle, '/proc/cpuinfo' ) or die "Can't open cpuinfo: $!\n"; + my $count = scalar( map /^processor/, <$handle> ); + close $handle; + + return $count; } sub find_files { diff --git a/scripts/runner.pl b/scripts/runner.pl index f11b6c5..37bb704 100644 --- a/scripts/runner.pl +++ b/scripts/runner.pl @@ -32,43 +32,6 @@ my $fail_server = "$fail_bin/generic-experiment-server"; my $fail_inject = "$fail_bin/generic-experiment-client"; my $result_browser = "$fail_bin/resultbrowser.py"; -sub update_db_config { - my ($experiment) = @_; - - open( my $readhandle, '<', $remote_db_conf ) - or die "failed to open db.conf: $!"; - my @lines; - my $found = 0; - while ( my $line = <$readhandle> ) { - if ( rindex( $line, 'database=', 0 ) == 0 ) { - $line = "database=${db_prefix}_$experiment\n"; - $found = 1; - } - push @lines, $line; - } - close($readhandle) or die "failed to close db.conf: $!"; - - die "no database= line found in $remote_db_conf for some reason" - unless $found; - - open( my $writehandle, '>', $remote_db_conf ) - or die "failed to open db.conf: $!"; - print $writehandle @lines or die "failed to write db.conf: $!"; - close($writehandle) or die "failed to close db.conf: $!"; - - say "Updated db.conf for database $db_prefix\_$experiment"; -} - -sub cpu_count { - open( my $handle, '/proc/cpuinfo' ) or die "Can't open cpuinfo: $!\n"; - my $count = scalar( map /^processor/, <$handle> ); - close $handle; - - return $count; -} - -my @experiments = Util::find_subdirs($remote_builds_dir); - sub trace { my ($experiment) = @_; @@ -194,8 +157,7 @@ sub import_trace { sub inject { my ($experiment) = @_; - # my $count = 1; - my $count = cpu_count(); + my $count = Util::cpu_count(); Util::notify("Injecting $experiment using $count cores..."); @@ -276,11 +238,13 @@ sub results { } # Run experiments +my @experiments = Util::find_subdirs($remote_builds_dir); for my $experiment (@experiments) { - update_db_config($experiment); + Util::rewrite_file( $remote_db_conf, "database=", + "database=${db_prefix}_$experiment\n" ); - # trace($experiment); - # import_trace($experiment); - # inject($experiment); + trace($experiment); + import_trace($experiment); + inject($experiment); results($experiment); }