1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-30 16:24:05 +03:00

Bug #55135 Collect times used in test execution phases in mtr

Adding option --report-times
Can't collect times if test run is aborted
This commit is contained in:
Bjorn Munch
2010-10-19 14:08:46 +02:00
parent e8fd5b58bf
commit 138ede4609
2 changed files with 116 additions and 1 deletions

View File

@ -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;