Merge pull request #190 from guriandoro/pt-stalk-collect-prepared-statements-LP1642750

pt stalk collect prepared statements lp1642750 (PT-90)
This commit is contained in:
Carlos Salguero
2017-07-02 23:32:22 -03:00
committed by GitHub
4 changed files with 82 additions and 6 deletions

View File

@@ -832,9 +832,7 @@ collect() {
$CMD_MYSQLADMIN $EXT_ARGV debug $CMD_MYSQLADMIN $EXT_ARGV debug
else else
log "Could not find the MySQL error log" log "Could not find the MySQL error log"
fi fi
if [ "${mysql_version}" '>' "5.1" ]; then if [ "${mysql_version}" '>' "5.1" ]; then
local mutex="SHOW ENGINE INNODB MUTEX" local mutex="SHOW ENGINE INNODB MUTEX"
else else
@@ -960,6 +958,10 @@ collect() {
ps_locks_transactions "$d/$p-ps-locks-transactions" ps_locks_transactions "$d/$p-ps-locks-transactions"
fi fi
if [ "${mysql_version}" '>' "5.6" ]; then
(echo $ts; ps_prepared_statements) >> "$d/$p-prepared-statements" &
fi
slave_status "$d/$p-slave-status" "${mysql_version}" slave_status "$d/$p-slave-status" "${mysql_version}"
curr_time=$(date +'%s') curr_time=$(date +'%s')
@@ -1126,6 +1128,13 @@ ps_locks_transactions() {
} }
ps_prepared_statements() {
$CMD_MYSQL $EXT_ARGV -e "SELECT t.processlist_id, pse.* \
FROM performance_schema.prepared_statements_instances pse \
JOIN performance_schema.threads t \
ON (pse.OWNER_THREAD_ID=t.thread_id)\G"
}
slave_status() { slave_status() {
local outfile=$1 local outfile=$1
local mysql_version=$2 local mysql_version=$2

View File

@@ -100,9 +100,7 @@ collect() {
$CMD_MYSQLADMIN $EXT_ARGV debug $CMD_MYSQLADMIN $EXT_ARGV debug
else else
log "Could not find the MySQL error log" log "Could not find the MySQL error log"
fi fi
# Get a sample of these right away, so we can get these without interaction # Get a sample of these right away, so we can get these without interaction
# with the other commands we're about to run. # with the other commands we're about to run.
if [ "${mysql_version}" '>' "5.1" ]; then if [ "${mysql_version}" '>' "5.1" ]; then
@@ -252,6 +250,10 @@ collect() {
ps_locks_transactions "$d/$p-ps-locks-transactions" ps_locks_transactions "$d/$p-ps-locks-transactions"
fi fi
if [ "${mysql_version}" '>' "5.6" ]; then
(echo $ts; ps_prepared_statements) >> "$d/$p-prepared-statements" &
fi
slave_status "$d/$p-slave-status" "${mysql_version}" slave_status "$d/$p-slave-status" "${mysql_version}"
curr_time=$(date +'%s') curr_time=$(date +'%s')
@@ -430,6 +432,13 @@ ps_locks_transactions() {
} }
ps_prepared_statements() {
$CMD_MYSQL $EXT_ARGV -e "SELECT t.processlist_id, pse.* \
FROM performance_schema.prepared_statements_instances pse \
JOIN performance_schema.threads t \
ON (pse.OWNER_THREAD_ID=t.thread_id)\G"
}
slave_status() { slave_status() {
local outfile=$1 local outfile=$1
local mysql_version=$2 local mysql_version=$2

View File

@@ -528,9 +528,56 @@ SKIP: {
); );
} }
# ###########################################################################
# Test report about performance schema prepared_statements_instances in MySQL 5.7+
# ###########################################################################
cleanup();
SKIP: {
skip "Only test on mysql 5.7" if ( $sandbox_version lt '5.7' );
sub start_thread_1642750 {
# this must run in a thread because we need to have an active session
# with prepared statements
my ($dsn_opts) = @_;
my $dp = new DSNParser(opts=>$dsn_opts);
my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp);
my $dbh = $sb->get_dbh_for('master');
$sb->load_file('master', "t/pt-stalk/samples/issue-1642750.sql");
}
my $thr = threads->create('start_thread_1642750', $dsn_opts);
$thr->detach();
threads->yield();
my $cmd = "$trunk/bin/pt-stalk --no-stalk --iterations=1 --host=127.0.0.1 --port=12345 --user=msandbox "
. "--password=msandbox --sleep 0 --run-time=10 --dest $dest --log $log_file --pid $pid_file "
. "--defaults-file=$cnf >$log_file 2>&1";
system($cmd);
sleep 15;
PerconaTest::kill_program(pid_file => $pid_file);
$output = `cat $dest/*-prepared-statements 2>/dev/null`;
like(
$output,
qr/ STATEMENT_NAME: rand_statement/,
"MySQL 5.7 prepared statement: rand_statement"
);
like(
$output,
qr/ STATEMENT_NAME: abs_statement/,
"MySQL 5.7 prepared statement: abs_statement"
);
}
# ############################################################################# # #############################################################################
# Done. # Done.
# ############################################################################# # #############################################################################
cleanup(); cleanup();
diag(`rm -rf $dest 2>/dev/null`); diag(`rm -rf $dest 2>/dev/null`);
ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox"); ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");

View File

@@ -0,0 +1,11 @@
/* Prepare two statements*/
SET @random_statement_prepare = 'SELECT RAND() AS rand';
PREPARE rand_statement FROM @random_statement_prepare;
SET @absolute_value_statement_prepare = 'SELECT ABS(?) AS abs_A';
PREPARE abs_statement FROM @absolute_value_statement_prepare;
/* Wait to let pt-stalk to collect the data and find these prepare statements */
SELECT SLEEP(11);