Skip to content

Commit d6bc29d

Browse files
committed
ktest.pl: Just open up the log file once
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) <[email protected]>
1 parent 1672342 commit d6bc29d

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

tools/testing/ktest/ktest.pl

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -509,9 +509,7 @@
509509

510510
sub _logit {
511511
if (defined($opt{"LOG_FILE"})) {
512-
open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
513-
print OUT @_;
514-
close(OUT);
512+
print LOG @_;
515513
}
516514
}
517515

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

17821780
if (defined($opt{"LOG_FILE"})) {
1783-
open(LOG, ">>$opt{LOG_FILE}") or
1784-
dodie "failed to write to log";
17851781
$dolog = 1;
17861782
}
17871783

@@ -1829,7 +1825,6 @@ sub run_command {
18291825
}
18301826

18311827
close(CMD);
1832-
close(LOG) if ($dolog);
18331828
close(RD) if ($dord);
18341829

18351830
$end_time = time;
@@ -4091,8 +4086,11 @@ sub make_warnings_file {
40914086
}
40924087
}
40934088

4094-
if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) {
4095-
unlink $opt{"LOG_FILE"};
4089+
if (defined($opt{"LOG_FILE"})) {
4090+
if ($opt{"CLEAR_LOG"}) {
4091+
unlink $opt{"LOG_FILE"};
4092+
}
4093+
open(LOG, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
40964094
}
40974095

40984096
doprint "\n\nSTARTING AUTOMATED TESTS\n\n";
@@ -4453,14 +4451,16 @@ sub cancel_test {
44534451
}
44544452

44554453

4456-
if (defined($opt{"LOG_FILE"})) {
4457-
print "\n See $opt{LOG_FILE} for the record of results.\n";
4458-
}
4459-
44604454
doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n";
44614455

44624456
if ($email_when_finished) {
44634457
send_email("KTEST: Your test has finished!",
44644458
"$successes of $opt{NUM_TESTS} tests started at $script_start_time were successful!");
44654459
}
4460+
4461+
if (defined($opt{"LOG_FILE"})) {
4462+
print "\n See $opt{LOG_FILE} for the record of results.\n\n";
4463+
close LOG;
4464+
}
4465+
44664466
exit 0;

0 commit comments

Comments
 (0)