2
# Copyright (C) 2000-2003, 2005 MySQL AB
4
# This library is free software; you can redistribute it and/or
5
# modify it under the terms of the GNU Library General Public
6
# License as published by the Free Software Foundation; version 2
9
# This library is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
# Library General Public License for more details.
14
# You should have received a copy of the GNU Library General Public
15
# License along with this library; if not, write to the Free
16
# Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
19
##########################################################
20
# this is the base file every test is using ....
21
# this is made for not changing every file if we want to
22
# add an option or just want to change something in
23
# code what is the same in every file ...
24
##########################################################
27
# The exported values are:
29
# $opt_... Various options
30
# $date Current date in ISO format
31
# $server Object for current server
32
# $limits Hash reference to limits for benchmark
34
$benchmark_version="2.15";
38
require "$pwd/server-cfg" || die "Can't read Configuration file: $!\n";
40
$|=1; # Output data immediately
42
our $opt_skip_test=$opt_skip_create=$opt_skip_delete=$opt_verbose=$opt_fast_insert=$opt_lock_tables=$opt_debug=$opt_skip_delete=$opt_fast=$opt_force=$opt_log=$opt_use_old_results=$opt_help=$opt_odbc=$opt_small_test=$opt_small_tables=$opt_samll_key_tables=$opt_stage=$opt_old_headers=$opt_die_on_errors=$opt_tcpip=$opt_random=$opt_only_missing_tests=0;
43
our $opt_cmp=$opt_user=$opt_password=$opt_connect_options="";
44
our $opt_create_options=undef;
46
our $opt_database="test";
47
our $opt_dir="output";
48
our $opt_host="localhost";
50
our $opt_server="mysql";
52
our $opt_optimization="None";
57
if (!defined($opt_time_limit))
59
$opt_time_limit=10*60; # Don't wait more than 10 min for some tests
62
$log_prog_args=join(" ", skip_arguments(\@ARGV,"comments","cmp","server",
63
"user", "host", "database", "password",
64
"use-old-results","skip-test",
66
"machine", "dir", "suffix", "log"));
113
"only-missing-tests",
114
"bzr-repo=s") || usage();
116
usage() if ($opt_help);
117
$server=get_server($opt_server,$opt_host,$opt_database,$opt_odbc,
118
machine_part(), $opt_socket, $opt_connect_options);
119
$limits=merge_limits($server,$opt_cmp);
121
@estimated=(0.0,0.0,0.0); # For estimated time support
125
eval "use Time::HiRes;";
129
my $tmp= $opt_server;
131
if (length($opt_cmp) && index($opt_cmp,$tmp) < 0)
136
$opt_cmp=lc(join(",",sort(split(',',$opt_cmp))));
139
# set opt_lock_tables if one uses --fast and drivers supports it
142
if (($opt_lock_tables || $opt_fast) && $server->{'limits'}->{'lock_tables'})
153
$opt_suffix="_fast" if (!length($opt_suffix));
158
$opt_suffix="_odbc" if (!length($opt_suffix));
163
print "Testing server '" . $server->version() . "' at $date\n\n";
168
print "\nCurrent limits: \n";
169
foreach $key (sort keys %$limits)
171
print $key . " " x (30-length($key)) . $limits->{$key} . "\n";
176
if (-d $opt_bzr_repo) {
177
$repo_version= `bzr revno $opt_bzr_repo`;
179
chomp($repo_version);
180
if (index($repo_version,'ERROR') > -1) {
181
usage("The bzr repository $opt_bzr_repo has a problem: $repo_version");
187
# Some help functions
192
my($argv,@skip_args)=@_;
193
my($skip,$arg,$name,@res);
195
foreach $arg (@$argv)
197
if ($arg =~ /^\-+([^=]*)/)
200
foreach $skip (@skip_args)
202
if (index($skip,$name) == 0)
204
$name=""; # Don't use this parameters
208
push (@res,$arg) if (length($name));
217
my ($server,$cmp)= @_;
218
my ($name,$tmp_server,$limits,$res_limits,$limit,$tmp_limits);
220
$res_limits=$server->{'limits'};
223
foreach $name (split(",",$cmp))
225
$tmp_server= (get_server($name,$opt_host, $opt_database,
226
$opt_odbc,machine_part())
227
|| die "Unknown SQL server: $name\n");
228
$limits=$tmp_server->{'limits'};
230
foreach $limit (keys(%$limits))
232
if (defined($res_limits->{$limit}) && defined($limits->{$limit}))
234
$new_limits{$limit}=min($res_limits->{$limit},$limits->{$limit});
237
%tmp_limits=%new_limits;
238
$res_limits=\%tmp_limits;
246
my ($sec, $min, $hour, $mday, $mon, $year) = localtime(time());
247
sprintf("%04d-%02d-%02d %2d:%02d:%02d",
248
1900+$year,$mon+1,$mday,$hour,$min,$sec);
255
for ($i=1 ; $i <= $#_; $i++)
257
$min=$_[$i] if ($min > $_[$i]);
266
for ($i=1 ; $i <= $#_; $i++)
268
$max=$_[$i] if ($max < $_[$i]);
275
# Execute many statements in a row
280
my ($dbh,@statements)=@_;
281
my ($statement,$sth);
283
foreach $statement (@statements)
285
if (!($sth=$dbh->do($statement)))
287
die "Can't execute command '$statement'\nError: $DBI::errstr\n";
294
my ($dbh,@statements)=@_;
295
my ($statement,$sth);
297
foreach $statement (@statements)
299
if (!($sth=$dbh->do($statement)))
301
print STDERR "Can't execute command '$statement'\nError: $DBI::errstr\n";
311
# Do a query and fetch all rows from a statement and return the number of rows
316
my ($dbh,$query,$must_get_result)=@_;
320
print "$query: " if ($opt_debug);
321
if (!($sth= $dbh->prepare($query)))
323
print "\n" if ($opt_debug);
324
die "Error occured with prepare($query)\n -> $DBI::errstr\n";
329
print "\n" if ($opt_debug);
330
if (defined($server->{'error_on_execute_means_zero_rows'}) &&
331
!$server->abort_if_fatal_error())
333
if (defined($must_get_result) && $must_get_result)
335
die "Error: Query $query didn't return any rows\n";
338
print "0\n" if ($opt_debug);
341
die "Error occured with execute($query)\n -> $DBI::errstr\n";
345
while ($sth->fetchrow_arrayref)
349
print "$count\n" if ($opt_debug);
350
if (defined($must_get_result) && $must_get_result && !$count)
352
die "Error: Query $query didn't return any rows\n";
362
print "$query\n" if ($opt_debug);
364
die "\nError executing '$query':\n$DBI::errstr\n";
368
# Run a query X times
371
sub time_fetch_all_rows
373
my($test_text,$result_text,$query,$dbh,$test_count)=@_;
374
my($i,$loop_time,$end_time,$count,$rows,$estimated);
376
print $test_text . "\n" if (defined($test_text));
378
$loop_time=new Benchmark;
379
for ($i=1 ; $i <= $test_count ; $i++)
382
$rows+=fetch_all_rows($dbh,$query) or die $DBI::errstr;
383
$end_time=new Benchmark;
384
last if ($estimated=predict_query_time($loop_time,$end_time,\$count,$i,
387
$end_time=new Benchmark;
389
{ print "Estimated time"; }
392
print " for $result_text ($count:$rows) " .
393
timestr(timediff($end_time, $loop_time),"all") . "\n\n";
398
# Handle estimated time of the server is too slow
399
# Returns 0 if one should continue as normal
402
sub predict_query_time
404
my ($loop_time,$end_time,$count_ref,$loop,$loop_count)= @_;
407
if (($end_time->[0] - $loop_time->[0]) > $opt_time_limit)
409
# We can't wait until the SUN dies. Try to predict the end time
410
if ($loop != $loop_count)
412
$tmp=($end_time->[0] - $loop_time->[0]);
413
print "Note: Query took longer then time-limit: $opt_time_limit\nEstimating end time based on:\n";
414
print "$$count_ref queries in $loop loops of $loop_count loops took $tmp seconds\n";
415
for ($k=0; $k < 3; $k++)
417
$tmp=$loop_time->[$k]+($end_time->[$k]-$loop_time->[$k])/$loop*
419
$estimated[$k]+=($tmp-$end_time->[$k]);
420
$end_time->[$k]=$tmp;
422
$$count_ref= int($$count_ref/$loop*$loop_count);
430
# standard end of benchmark
437
$end_time=new Benchmark;
440
print "Estimated total time: ";
441
$end_time->[0]+=$estimated[0];
442
$end_time->[1]+=$estimated[1];
443
$end_time->[2]+=$estimated[2];
449
print timestr(timediff($end_time, $start_time),"all") . "\n";
457
{ print "Estimated time"; }
468
my $error_msg= $_[0];
469
print "ERROR: $error_msg\n\n";
471
The MySQL benchmarks Ver $benchmark_version
473
All benchmarks takes the following options:
476
Specifies a bazaar repository directory for the test suite to obtain the
477
repo version which it then uses as part of the results output filenames
480
Add a comment to the benchmark output. Comments should contain
481
extra information that 'uname -a' doesn\'t give and if the database was
482
stared with some specific, non default, options.
484
--cmp=server[,server...]
485
Run the test with limits from the given servers. If you run all servers
486
with the same --cmp, you will get a test that is comparable between
487
the different sql servers.
490
Extra argument to all create statements. If you for example want to
491
create all MySQL tables as InnoDB tables use:
492
--create-options=ENGINE=InnoDB
494
--database (Default $opt_database)
495
In which database the test tables are created.
498
This is a test specific option that is only used when debugging a test.
499
Print out debugging information.
501
--dir (Default $opt_dir)
502
Option to 'run-all-tests' to where the test results should be stored.
505
Allow the database to use non standard ANSI SQL commands to make the
509
Use "insert into table_name values(...)" instead of
510
"insert into table_name (....) values(...)"
511
If the database supports it, some tests uses multiple value lists.
514
This is a test specific option that is only used when debugging a test.
515
This usually means how many fields there should be in the test table.
518
This is a test specific option that is only used when debugging a test.
519
Continue the test even if there is some error.
520
Delete tables before creating new ones.
522
--groups (Default $opt_groups)
523
This is a test specific option that is only used when debugging a test.
524
This usually means how many different groups there should be in the test.
527
Allow the database to use table locking to get more speed.
530
Option to 'run-all-tests' to save the result to the '--dir' directory.
532
--loop-count (Default $opt_loop_count)
533
This is a test specific option that is only used when debugging a test.
534
This usually means how many times times each test loop is executed.
539
--host='host name' (Default $opt_host)
540
Host name where the database server is located.
542
--machine="machine or os_name"
543
The machine/os name that is added to the benchmark output filename.
544
The default is the OS name + version.
547
Use the ODBC DBI driver to connect to the database.
550
Only run test that don\'t have an old test result.
551
This is useful when you want to do a re-run of tests that failed in last run.
553
--optimization='some comments'
554
Add coments about optimization of DBMS, which was done before the test.
556
--password='password'
557
Password for the current user.
560
If the database supports connecting through a Unix socket,
561
then use this socket to connect
564
This is a test specific option that is only used when debugging a test.
565
This usually means how AND levels should be tested.
568
Get the old benchmark headers from the old RUN- file.
570
--server='server name' (Default $opt_server)
571
Run the test on the given SQL server.
572
Known servers names are: Access, Adabas, AdabasD, Empress, Oracle,
573
Informix, DB2, mSQL, MS-SQL, MySQL, Pg, Solid and Sybase
576
Don't print info about the server when starting test.
579
This is a test specific option that is only used when debugging a test.
580
This will keep the test tables after the test is run.
582
--skip-test=test1[,test2,...]
583
For run-all-programs; Don\'t execute the named tests.
586
This runs some tests with smaller limits to get a faster test.
587
Can be used if you just want to verify that the database works, but
588
don't have time to run a full test.
591
This runs some tests that generate big tables with fewer rows.
592
This can be used with databases that can\'t handle that many rows
593
because of pre-sized partitions.
595
--suffix (Default $opt_suffix)
596
The suffix that is added to the database name in the benchmark output
597
filename. This can be used to run the benchmark multiple times with
598
different server options without overwritten old files.
599
When using --fast the suffix is automaticly set to '_fast'.
602
Inform test suite that we are generate random inital values for sequence of
603
test executions. It should be used for imitation of real conditions.
605
--threads=# (Default 5)
606
Number of threads for multi-user benchmarks.
609
Inform test suite that we are using TCP/IP to connect to the server. In
610
this case we can\t do many new connections in a row as we in this case may
611
fill the TCP/IP stack
613
--time-limit (Default $opt_time_limit)
614
How long a test loop is allowed to take, in seconds, before the end result
618
Option to 'run-all-tests' to use the old results from the '--dir' directory
619
instead of running the tests.
622
User name to log into the SQL server.
625
This is a test specific option that is only used when debugging a test.
626
Print more information about what is going on.
629
Add coments about hardware used for this test.
631
--connect-options='some connect options'
632
Add options, which uses at DBI connect.
633
For example --connect-options=mysql_read_default_file=/etc/my.cnf.
642
#### The end of the base file ...