Skip to content

Commit a2a1fa2

Browse files
author
Srikanth B R
committed
Bug#30429863 MTR: BACKPORT FIX RELATED TO VALGRIND TOOLS
This is a backport of the patch for 'Bug#23713613: MTR DOES NOT ALLOW VALGRIND TO BE RUN WITH CUSTOM TOOL' Issue ===== - MTR can not be run with --valgrind-option=--tool=<custom_tool> like massif/helgrind as it always adds the options for memcheck which can be invalid for other tools. - The MTR --callgrind option does not work as it supplies an invalid callgrind argument '--base'. Fix === - The patch restructures MTR to allow usage of the command line option --valgrind-option=--tool=<custom_tool> and removes the invalid option '--base' which was being supplied to callgrind. - In addition, valgrind logs for tools like callgrind and massif are generated in the location <vardir>/log Change-Id: I1b1e02061f3c029bb89818aee2f113f2b9effbfb
1 parent 045c87e commit a2a1fa2

File tree

2 files changed

+59
-30
lines changed

2 files changed

+59
-30
lines changed

mysql-test/include/mtr_warnings.sql

+8
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,14 @@ INSERT INTO global_suppressions VALUES
204204
("==[0-9]*== Warning: set address range perms: large range"),
205205
/* valgrind-3.5.0 dumps this */
206206
("==[0-9]*== Command: "),
207+
/* Messages from valgrind tools */
208+
("==[0-9]*== Callgrind"),
209+
("==[0-9]*== For interactive control, run 'callgrind_control -h'"),
210+
("==[0-9]*== Events :"),
211+
("==[0-9]*== Collected : [0-9]+"),
212+
("==[0-9]*== I refs: [0-9]+"),
213+
("==[0-9]*== Massif"),
214+
("==[0-9]*== Helgrind"),
207215

208216
/* valgrind warnings: invalid file descriptor -1 in syscall
209217
write()/read(). Bug #50414 */

mysql-test/mysql-test-run.pl

+51-30
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,6 @@ END
302302
our $opt_valgrind= 0;
303303
my $opt_valgrind_mysqld= 0;
304304
my $opt_valgrind_mysqltest= 0;
305-
my @default_valgrind_args= ("--show-reachable=yes");
306305
my @valgrind_args;
307306
my $opt_valgrind_path;
308307
my $valgrind_reports= 0;
@@ -1687,6 +1686,16 @@ sub command_line_setup {
16871686
"for option --testsuite-timeout")
16881687
if ($opt_suite_timeout <= 0);
16891688

1689+
# --------------------------------------------------------------------------
1690+
# Check trace protocol option
1691+
# --------------------------------------------------------------------------
1692+
if ( $opt_trace_protocol )
1693+
{
1694+
push(@opt_extra_mysqld_opt, "--optimizer_trace=enabled=on,one_line=off");
1695+
# Some queries yield big traces:
1696+
push(@opt_extra_mysqld_opt, "--optimizer-trace-max-mem-size=1000000");
1697+
}
1698+
16901699
# --------------------------------------------------------------------------
16911700
# Check valgrind arguments
16921701
# --------------------------------------------------------------------------
@@ -1720,32 +1729,40 @@ sub command_line_setup {
17201729
$opt_valgrind= 1;
17211730
$opt_valgrind_mysqld= 1;
17221731

1723-
# Set special valgrind options unless options passed on command line
1724-
push(@valgrind_args, "--trace-children=yes")
1725-
unless @valgrind_args;
1726-
}
1732+
push(@valgrind_args, "--tool=callgrind", "--trace-children=yes");
17271733

1728-
if ( $opt_trace_protocol )
1729-
{
1730-
push(@opt_extra_mysqld_opt, "--optimizer_trace=enabled=on,one_line=off");
1731-
# some queries yield big traces:
1732-
push(@opt_extra_mysqld_opt, "--optimizer-trace-max-mem-size=1000000");
1734+
# Increase the timeouts when running with callgrind
1735+
$opt_testcase_timeout*= 10;
1736+
$opt_suite_timeout*= 6;
1737+
$opt_start_timeout*= 10;
1738+
$opt_debug_sync_timeout*= 10;
17331739
}
17341740

1735-
if ( $opt_valgrind )
1741+
if ($opt_valgrind)
17361742
{
1737-
# Set valgrind_options to default unless already defined
1738-
push(@valgrind_args, @default_valgrind_args)
1739-
unless @valgrind_args;
1743+
# Default to --tool=memcheck if no other tool has been explicitly
1744+
# specified. From >= 2.1.2, this option is needed
1745+
if (!@valgrind_args or !grep(/^--tool=/, @valgrind_args))
1746+
{
1747+
# Set default valgrind options for memcheck, can be overriden by user
1748+
unshift(@valgrind_args, ("--tool=memcheck", "--num-callers=16",
1749+
"--show-reachable=yes"));
1750+
}
17401751

1741-
# Don't add --quiet; you will loose the summary reports.
1752+
# Add suppression file if not specified
1753+
if (!grep(/^--suppressions=/, @valgrind_args))
1754+
{
1755+
push(@valgrind_args,"--suppressions=${glob_mysql_test_dir}/valgrind.supp")
1756+
if -f "$glob_mysql_test_dir/valgrind.supp";
1757+
}
17421758

1759+
# Don't add --quiet; you will loose the summary reports.
17431760
mtr_report("Running valgrind with options \"",
1744-
join(" ", @valgrind_args), "\"");
1745-
1761+
join(" ", @valgrind_args), "\"");
1762+
17461763
# Turn off check testcases to save time
17471764
mtr_report("Turning off --check-testcases to save time when valgrinding");
1748-
$opt_check_testcases = 0;
1765+
$opt_check_testcases = 0;
17491766
}
17501767

17511768
if ($opt_debug_common)
@@ -5304,7 +5321,7 @@ ($$)
53045321

53055322
if ( $opt_valgrind_mysqld )
53065323
{
5307-
valgrind_arguments($args, \$exe);
5324+
valgrind_arguments($args, \$exe, $mysqld->name());
53085325
}
53095326

53105327
mtr_add_arg($args, "--defaults-group-suffix=%s", $mysqld->after('mysqld'));
@@ -6335,19 +6352,23 @@ sub strace_server_arguments {
63356352
sub valgrind_arguments {
63366353
my $args= shift;
63376354
my $exe= shift;
6355+
my $report_prefix= shift;
63386356

6339-
if ( $opt_callgrind)
6357+
if (my @tool_list= grep(/^--tool=(memcheck|callgrind|massif)/, @valgrind_args))
63406358
{
6341-
mtr_add_arg($args, "--tool=callgrind");
6342-
mtr_add_arg($args, "--base=$opt_vardir/log");
6343-
}
6344-
else
6345-
{
6346-
mtr_add_arg($args, "--tool=memcheck"); # From >= 2.1.2 needs this option
6347-
mtr_add_arg($args, "--leak-check=yes");
6348-
mtr_add_arg($args, "--num-callers=16");
6349-
mtr_add_arg($args, "--suppressions=%s/valgrind.supp", $glob_mysql_test_dir)
6350-
if -f "$glob_mysql_test_dir/valgrind.supp";
6359+
# Get the value of the last specified --tool=<> argument to valgrind
6360+
my ($tool_name)= $tool_list[-1] =~ /(memcheck|callgrind|massif)$/;
6361+
if ($tool_name=~ /memcheck/)
6362+
{
6363+
mtr_add_arg($args, "--leak-check=yes") ;
6364+
}
6365+
else
6366+
{
6367+
$$exe=~ /.*[\/](.*)$/;
6368+
my $report_prefix= defined $report_prefix ? $report_prefix : $1;
6369+
mtr_add_arg($args, "--$tool_name-out-file=$opt_vardir/log/".
6370+
"$report_prefix"."_$tool_name.out.%%p");
6371+
}
63516372
}
63526373

63536374
# Add valgrind options, can be overriden by user

0 commit comments

Comments
 (0)