[PATCH] ktest.pl: Add total run time to email
From: Steven Rostedt
Date: Mon Nov 30 2026 - 14:10:38 EST
From: Steven Rostedt <rostedt@xxxxxxxxxxx>
When ktest finishes, it outputs the total test time. This is useful
information to include in the email so that it is recorded.
Move the "stop time" to just before sending the email (where it currently
is just after) and have the email show the total time as well as
outputting it to the screen.
Signed-off-by: Steven Rostedt <rostedt@xxxxxxxxxxx>
---
tools/testing/ktest/ktest.pl | 44 ++++++++++++++++++++++++++----------
1 file changed, 32 insertions(+), 12 deletions(-)
diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl
index 66fd98b6b04b..982bf067a721 100755
--- a/tools/testing/ktest/ktest.pl
+++ b/tools/testing/ktest/ktest.pl
@@ -687,9 +687,11 @@ sub get_mandatory_config {
}
}
-sub show_time {
+sub make_time {
my ($time) = @_;
+ my $t = "";
+
my $hours = 0;
my $minutes = 0;
@@ -703,19 +705,29 @@ sub show_time {
}
if ($hours > 0) {
- doprint "$hours hour";
- doprint "s" if ($hours > 1);
- doprint " ";
+ $t .= "$hours hour";
+ $t .= "s" if ($hours > 1);
+ $t .= " ";
}
if ($minutes > 0) {
- doprint "$minutes minute";
- doprint "s" if ($minutes > 1);
- doprint " ";
+ $t .= "$minutes minute";
+ $t .= "s" if ($minutes > 1);
+ $t .= " ";
}
- doprint "$time second";
- doprint "s" if ($time != 1);
+ $t .= "$time second";
+ $t .= "s" if ($time != 1);
+
+ return $t;
+}
+
+sub show_time {
+ my ($time) = @_;
+
+ my $this_time = make_time $time;
+
+ doprint $this_time;
}
sub print_times {
@@ -1610,11 +1622,14 @@ sub run_post_ktest {
$post_ktest_done = 1;
}
+my $total_run_time;
+
sub show_run_time {
return if (!$start_run_time);
my $end_run_time = time;
+ $total_run_time = $end_run_time - $start_run_time;
doprint "\n Total run time: ";
- show_time($end_run_time - $start_run_time);
+ show_time($total_run_time);
doprint "\n";
}
@@ -4355,6 +4370,11 @@ sub do_send_mail {
print HEAD "To: $mailto\n";
print HEAD "Subject: $subject\n\n";
print HEAD "$message\n";
+ if (defined($total_run_time)) {
+ print HEAD "\n Total run time: ";
+ my $t = make_time $total_run_time;
+ print HEAD "$t\n";
+ }
close HEAD;
if (!defined($mail_command)) {
@@ -4774,13 +4794,13 @@ if ($opt{"POWEROFF_ON_SUCCESS"}) {
doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n";
+show_run_time();
+
if ($email_when_finished) {
send_email("KTEST: Your test has finished!",
"$successes of $opt{NUM_TESTS} tests started at $script_start_time were successful!");
}
-show_run_time();
-
if (defined($opt{"LOG_FILE"})) {
print "\n See $opt{LOG_FILE} for the record of results.\n\n";
close LOG;
--
2.53.0