Skip to content

Commit

Permalink
ktest.pl: Just open up the log file once
Browse files Browse the repository at this point in the history
Currently, every write to the log file is done by opening the file, writing
to it, then closing the file. This rather expensive. Just open it at the
beginning and close it at the end.

Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
  • Loading branch information
Steven Rostedt (VMware) committed Jul 1, 2020
1 parent 1672342 commit d6bc29d
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions tools/testing/ktest/ktest.pl
Original file line number Diff line number Diff line change
Expand Up @@ -509,9 +509,7 @@

sub _logit {
if (defined($opt{"LOG_FILE"})) {
open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
print OUT @_;
close(OUT);
print LOG @_;
}
}

Expand Down Expand Up @@ -1780,8 +1778,6 @@ sub run_command {
(fail "unable to exec $command" and return 0);

if (defined($opt{"LOG_FILE"})) {
open(LOG, ">>$opt{LOG_FILE}") or
dodie "failed to write to log";
$dolog = 1;
}

Expand Down Expand Up @@ -1829,7 +1825,6 @@ sub run_command {
}

close(CMD);
close(LOG) if ($dolog);
close(RD) if ($dord);

$end_time = time;
Expand Down Expand Up @@ -4091,8 +4086,11 @@ sub make_warnings_file {
}
}

if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) {
unlink $opt{"LOG_FILE"};
if (defined($opt{"LOG_FILE"})) {
if ($opt{"CLEAR_LOG"}) {
unlink $opt{"LOG_FILE"};
}
open(LOG, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
}

doprint "\n\nSTARTING AUTOMATED TESTS\n\n";
Expand Down Expand Up @@ -4453,14 +4451,16 @@ sub cancel_test {
}


if (defined($opt{"LOG_FILE"})) {
print "\n See $opt{LOG_FILE} for the record of results.\n";
}

doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n";

if ($email_when_finished) {
send_email("KTEST: Your test has finished!",
"$successes of $opt{NUM_TESTS} tests started at $script_start_time were successful!");
}

if (defined($opt{"LOG_FILE"})) {
print "\n See $opt{LOG_FILE} for the record of results.\n\n";
close LOG;
}

exit 0;

0 comments on commit d6bc29d

Please sign in to comment.