move update_db_config to util
This commit is contained in:
@ -15,6 +15,8 @@ sub notify {
|
|||||||
|
|
||||||
system( 'curl', '-H', "Authorization: Bearer $ntfy_token",
|
system( 'curl', '-H', "Authorization: Bearer $ntfy_token",
|
||||||
'-d', $msg, "$ntfy_url/$ntfy_topic" );
|
'-d', $msg, "$ntfy_url/$ntfy_topic" );
|
||||||
|
|
||||||
|
sleep(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
sub notify_file {
|
sub notify_file {
|
||||||
@ -25,6 +27,40 @@ sub notify_file {
|
|||||||
'-T', $file, '-H', "Filename: $file",
|
'-T', $file, '-H', "Filename: $file",
|
||||||
"$ntfy_url/$ntfy_topic"
|
"$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 {
|
sub find_files {
|
||||||
|
|||||||
@ -32,43 +32,6 @@ my $fail_server = "$fail_bin/generic-experiment-server";
|
|||||||
my $fail_inject = "$fail_bin/generic-experiment-client";
|
my $fail_inject = "$fail_bin/generic-experiment-client";
|
||||||
my $result_browser = "$fail_bin/resultbrowser.py";
|
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 {
|
sub trace {
|
||||||
my ($experiment) = @_;
|
my ($experiment) = @_;
|
||||||
|
|
||||||
@ -194,8 +157,7 @@ sub import_trace {
|
|||||||
sub inject {
|
sub inject {
|
||||||
my ($experiment) = @_;
|
my ($experiment) = @_;
|
||||||
|
|
||||||
# my $count = 1;
|
my $count = Util::cpu_count();
|
||||||
my $count = cpu_count();
|
|
||||||
|
|
||||||
Util::notify("Injecting $experiment using $count cores...");
|
Util::notify("Injecting $experiment using $count cores...");
|
||||||
|
|
||||||
@ -276,11 +238,13 @@ sub results {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Run experiments
|
# Run experiments
|
||||||
|
my @experiments = Util::find_subdirs($remote_builds_dir);
|
||||||
for my $experiment (@experiments) {
|
for my $experiment (@experiments) {
|
||||||
update_db_config($experiment);
|
Util::rewrite_file( $remote_db_conf, "database=",
|
||||||
|
"database=${db_prefix}_$experiment\n" );
|
||||||
|
|
||||||
# trace($experiment);
|
trace($experiment);
|
||||||
# import_trace($experiment);
|
import_trace($experiment);
|
||||||
# inject($experiment);
|
inject($experiment);
|
||||||
results($experiment);
|
results($experiment);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user