summaryrefslogtreecommitdiff
path: root/mysql-test/lib/mtr_misc.pl
diff options
context:
space:
mode:
authorBjorn Munch <bjorn.munch@oracle.com>2010-10-19 14:08:46 +0200
committerBjorn Munch <bjorn.munch@oracle.com>2010-10-19 14:08:46 +0200
commit138ede4609be43e177ecd60d3e4778647f8f35fd (patch)
tree8155ba35f4836ba477844e10b60dec376b09f8f1 /mysql-test/lib/mtr_misc.pl
parente8fd5b58bff9bc06012c8758ce76b39ba51e6712 (diff)
downloadmariadb-git-138ede4609be43e177ecd60d3e4778647f8f35fd.tar.gz
Bug #55135 Collect times used in test execution phases in mtr
Adding option --report-times Can't collect times if test run is aborted
Diffstat (limited to 'mysql-test/lib/mtr_misc.pl')
-rw-r--r--mysql-test/lib/mtr_misc.pl84
1 files changed, 84 insertions, 0 deletions
diff --git a/mysql-test/lib/mtr_misc.pl b/mysql-test/lib/mtr_misc.pl
index 32960d866ce..dc9928d37c5 100644
--- a/mysql-test/lib/mtr_misc.pl
+++ b/mysql-test/lib/mtr_misc.pl
@@ -33,6 +33,13 @@ sub mtr_exe_maybe_exists(@);
sub mtr_milli_sleep($);
sub start_timer($);
sub has_expired($);
+sub init_timers();
+sub mark_time_used($);
+sub add_total_times($);
+sub print_times_used($$);
+sub print_total_times($);
+
+our $opt_report_times;
##############################################################################
#
@@ -205,4 +212,81 @@ sub start_timer ($) { return time + $_[0]; }
sub has_expired ($) { return $_[0] && time gt $_[0]; }
+# Below code is for time usage reporting
+
+use Time::HiRes qw(gettimeofday);
+
+my %time_used= (
+ 'collect' => 0,
+ 'restart' => 0,
+ 'check' => 0,
+ 'ch-warn' => 0,
+ 'test' => 0,
+ 'init' => 0,
+);
+
+my %time_text= (
+ 'collect' => "Collecting test cases",
+ 'restart' => "Server stop/start",
+ 'check' => "Check-testcase",
+ 'ch-warn' => "Check for warnings",
+ 'test' => "Test execution",
+ 'init' => "Initialization etc.",
+);
+
+# Counts number of reports from workers
+
+my $time_totals= 0;
+
+my $last_timer_set;
+
+sub init_timers() {
+ $last_timer_set= gettimeofday();
+}
+
+sub mark_time_used($) {
+ my ($name)= @_;
+ return unless $opt_report_times;
+ die "Unknown timer $name" unless exists $time_used{$name};
+
+ my $curr_time= gettimeofday();
+ $time_used{$name}+= int (($curr_time - $last_timer_set) * 1000 + .5);
+ $last_timer_set= $curr_time;
+}
+
+sub add_total_times($) {
+ my ($dummy, $num, @line)= split (" ", $_[0]);
+
+ $time_totals++;
+ foreach my $elem (@line) {
+ my ($name, $spent)= split (":", $elem);
+ $time_used{$name}+= $spent;
+ }
+}
+
+sub print_times_used($$) {
+ my ($server, $num)= @_;
+ return unless $opt_report_times;
+
+ my $output= "SPENT $num";
+ foreach my $name (keys %time_used) {
+ my $spent= $time_used{$name};
+ $output.= " $name:$spent";
+ }
+ print $server $output . "\n";
+}
+
+sub print_total_times($) {
+ # Don't print if we haven't received all worker data
+ return if $time_totals != $_[0];
+
+ foreach my $name (keys %time_used)
+ {
+ my $spent= $time_used{$name}/1000;
+ my $text= $time_text{$name};
+ print ("Spent $spent seconds on $text\n");
+ }
+}
+
+
1;