/usr/lib/mysql-testsuite/t/dynamic_tracing.test is in percona-server-test-5.6 5.6.22-rel71.0-0ubuntu4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | # This scripts checks dtrace probes provided by mysqld using real dtrace tool
# and systemtap.
--source include/not_windows.inc
--let OUTPUT_FILENAME= $MYSQLTEST_VARDIR/tmp/output.txt
--let MYSQLD_PIDFILE= `SELECT @@pid_file`
--let MYSQLD= $MYSQLD
--let SCRIPT_OUTPUT_FILE= $MYSQLTEST_VARDIR/tmp/script_output.txt
--perl
my $pid_filename = $ENV{'MYSQLD_PIDFILE'};
my $output_filename = $ENV{'OUTPUT_FILENAME'};
my $mysqld = $ENV{'MYSQLD'};
my $mysqld_pid = 0;
my $dyn_trace_tool_available = 0;
my $user_has_permissions = 0;
my $mysqld_has_dtrace_probes = 0;
my $command = "";
my $ret;
# Check whether Dtrace tool exists or not. If exists then capture its output.
$ret = `dtrace -V 2>&1`;
if ($? == 0)
{
if (($ret =~ m/Sun D/) || ($ret =~ m/Oracle D/))
{
$dyn_trace_tool_available = 1;
# Check whether user has Dtrace tool execution permission or not
$ret = `dtrace -v 2>&1`;
if (!($ret =~ m/DTrace requires additional privileges/))
{
$user_has_permissions = 1;
$mysqld_pid= `cat $pid_filename`;
chomp($mysqld_pid);
# Check whether MySQL Dtrace providers exists or not.
$ret=`dtrace -l -p $mysqld_pid |
egrep -ci \"net-read-done|connection-start|query-parse-start\"`;
if ($ret != 0)
{
$mysqld_has_dtrace_probes = 1;
$command = "dtrace -s \$MYSQL_TEST_DIR/std_data/dtrace.d ";
}
}
}
}
else
{
# check whether stap tool exists or not.
$ret= `stap 2>&1`;
if ($ret == 0)
{
$dyn_trace_tool_available= 1;
# Check whether user has permission to run stap.
$ret= `stap -e 'probe process("ls").function("main") { exit() }'
-c ls 2>&1|egrep -ic "You should be part of the group \"stapusr"`;
# Check whether user has permission to run staprun or not.
if ($ret == 0)
{
$ret= `staprun 2>&1|egrep -ic "Permission denied"`;
}
if ($ret == 0)
{
$user_has_permissions= 1;
# Check whether MySQL stap markers are available or not.
$ret= `stap -L 'process("$mysqld").mark("*")'|
egrep -ci \"net__read__done|connection__start|query__parse__start\"`;
if ($ret != 0)
{
$mysqld_has_dtrace_probes = 1;
$command= "stap \$MYSQL_TEST_DIR/std_data/system_tap.stp $mysqld ";
}
}
}
}
# Write output to file.
open(FILE, ">> $output_filename");
print FILE "--let \$DYN_TRACE_TOOL_AVAILABLE= $dyn_trace_tool_available\n";
print FILE "--let \$USER_HAS_PERMISSIONS= $user_has_permissions\n";
print FILE "--let \$MYSQLD_HAS_DTRACE_PROBES= $mysqld_has_dtrace_probes\n";
print FILE "--let COMMAND= $command\n";
close(FILE);
EOF
source $OUTPUT_FILENAME;
if (!$DYN_TRACE_TOOL_AVAILABLE)
{
--skip Real DTrace or System tap tool is required to run this test.
}
if (!$USER_HAS_PERMISSIONS)
{
--skip dtrace/stap tool requires additional privileges to run this test.
}
if (!$MYSQLD_HAS_DTRACE_PROBES)
{
--skip MySQLD does not have MySQL probes.
}
--disable_result_log
DELIMITER $;
CREATE PROCEDURE create_table_and_insert_rows()
BEGIN
DECLARE count INT;
SET count = 1;
SELECT SLEEP(10);
CREATE TABLE t1 (f1 INT);
INSERT INTO t1 VALUES (7894);
WHILE count <= 5 DO
INSERT INTO t1 SELECT * FROM t1;
SET count = count + 1;
END WHILE;
SET count = 1;
WHILE count <= 10000 DO
SELECT SQL_NO_CACHE count(*) from t1;
SET count = count + 1;
END WHILE;
END
$
DELIMITER ;$
# Running Dtrace script in background.
--perl
system("$ENV{'COMMAND'} >$ENV{'SCRIPT_OUTPUT_FILE'} 2>&1 &");
EOF
CALL create_table_and_insert_rows();
# Waiting for few secs to allow Dtrace to write all trace output to file.
SELECT SLEEP(4);
--enable_result_log
# Dtrace output
--exec cat $SCRIPT_OUTPUT_FILE
# Cleanup
--remove_file $OUTPUT_FILENAME
--remove_file $SCRIPT_OUTPUT_FILE
DROP TABLE t1;
DROP PROCEDURE create_table_and_insert_rows;
|