1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335
|
# -*- cperl -*-
# Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
# License as published by the Free Software Foundation; version 2
# of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Library General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
# This is a library file used by the Perl version of mysql-test-run,
# and is part of the translation of the Bourne shell script with the
# same name.
use strict;
use My::Platform;
sub mtr_init_args ($);
sub mtr_add_arg ($$@);
sub mtr_args2str($@);
sub mtr_path_exists(@);
sub mtr_script_exists(@);
sub mtr_file_exists(@);
sub mtr_exe_exists(@);
sub mtr_exe_maybe_exists(@);
sub mtr_compress_file($);
sub mtr_milli_sleep($);
sub start_timer($);
sub has_expired($);
sub init_timers();
sub mark_time_used($);
sub mark_time_idle();
sub add_total_times($);
sub print_times_used($$);
sub print_total_times($);
our $opt_report_times;
##############################################################################
#
# Args
#
##############################################################################
sub mtr_init_args ($) {
my $args = shift;
$$args = []; # Empty list
}
sub mtr_add_arg ($$@) {
my $args= shift;
my $format= shift;
my @fargs = @_;
# Quote args if args contain space
$format= "\"$format\""
if (IS_WINDOWS and grep(/\s/, @fargs));
push(@$args, sprintf($format, @fargs));
}
sub mtr_args2str($@) {
my $exe= shift or die;
return join(" ", native_path($exe), @_);
}
##############################################################################
#
# NOTE! More specific paths should be given before less specific.
# For example /client/debug should be listed before /client
#
sub mtr_path_exists (@) {
foreach my $path ( @_ )
{
return $path if -e $path;
}
if ( @_ == 1 )
{
mtr_error("Could not find $_[0]");
}
else
{
mtr_error("Could not find any of " . join(" ", @_));
}
}
#
# NOTE! More specific paths should be given before less specific.
# For example /client/debug should be listed before /client
#
sub mtr_script_exists (@) {
foreach my $path ( @_ )
{
if(IS_WINDOWS)
{
return $path if -f $path;
}
else
{
return $path if -x $path;
}
}
if ( @_ == 1 )
{
mtr_error("Could not find $_[0]");
}
else
{
mtr_error("Could not find any of " . join(" ", @_));
}
}
#
# NOTE! More specific paths should be given before less specific.
# For example /client/debug should be listed before /client
#
sub mtr_file_exists (@) {
foreach my $path ( @_ )
{
return $path if -e $path;
}
return "";
}
#
# NOTE! More specific paths should be given before less specific.
# For example /client/debug should be listed before /client
#
sub mtr_exe_maybe_exists (@) {
my @path= @_;
map {$_.= ".exe"} @path if IS_WINDOWS;
foreach my $path ( @path )
{
if(IS_WINDOWS)
{
return $path if -f $path;
}
else
{
return $path if -x $path;
}
}
return "";
}
#
# NOTE! More specific paths should be given before less specific.
#
sub mtr_pl_maybe_exists (@) {
my @path= @_;
map {$_.= ".pl"} @path if IS_WINDOWS;
foreach my $path ( @path )
{
if(IS_WINDOWS)
{
return $path if -f $path;
}
else
{
return $path if -x $path;
}
}
return "";
}
#
# NOTE! More specific paths should be given before less specific.
# For example /client/debug should be listed before /client
#
sub mtr_exe_exists (@) {
my @path= @_;
if (my $path= mtr_exe_maybe_exists(@path))
{
return $path;
}
# Could not find exe, show error
if ( @path == 1 )
{
mtr_error("Could not find $path[0]");
}
else
{
mtr_error("Could not find any of " . join(" ", @path));
}
}
#
# Try to compress file using tools that might be available.
# If zip/gzip is not available, just silently ignore.
#
sub mtr_compress_file ($) {
my ($filename)= @_;
mtr_error ("File to compress not found: $filename") unless -f $filename;
my $did_compress= 0;
if (IS_WINDOWS)
{
# Capture stderr
my $ziperr= `zip $filename.zip $filename 2>&1`;
if ($?) {
print "$ziperr\n" if $ziperr !~ /recognized as an internal or external/;
} else {
unlink($filename);
$did_compress=1;
}
}
else
{
my $gzres= system("gzip $filename");
$did_compress= ! $gzres;
if ($gzres && $gzres != -1) {
mtr_error ("Error: have gzip but it fails to compress core file");
}
}
mtr_print("Compressed file $filename") if $did_compress;
}
sub mtr_milli_sleep ($) {
die "usage: mtr_milli_sleep(milliseconds)" unless @_ == 1;
my ($millis)= @_;
select(undef, undef, undef, ($millis/1000));
}
# Simple functions to start and check timers (have to be actively polled)
# Timer can be "killed" by setting it to 0
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,
'admin' => 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/cleanup",
'admin' => "Test administration",
);
# 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 mark_time_idle() {
$last_timer_set= gettimeofday() if $opt_report_times;
}
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;
|