mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-12-21 02:00:45 +08:00
Merge pull request #188 from percona/issue-1642751
Issue 1642751 Collect information about locks and transactions using P_S
This commit is contained in:
38
bin/pt-stalk
38
bin/pt-stalk
@@ -832,6 +832,7 @@ collect() {
|
||||
log "Could not find the MySQL error log"
|
||||
fi
|
||||
|
||||
|
||||
if [ "${mysql_version}" '>' "5.1" ]; then
|
||||
local mutex="SHOW ENGINE INNODB MUTEX"
|
||||
else
|
||||
@@ -904,6 +905,12 @@ collect() {
|
||||
log "Loop start: $(date +'TS %s.%N %F %T')"
|
||||
local start_time=$(date +'%s')
|
||||
local curr_time=$start_time
|
||||
local ps_instrumentation_enabled=$($CMD_MYSQL $EXT_ARGV -e 'SELECT ENABLED FROM performance_schema.setup_instruments WHERE NAME = "transaction";' \
|
||||
| sed "2q;d" | sed 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/')
|
||||
if [ $ps_instrumentation_enabled != "yes" ]; then
|
||||
log "Performance Schema instrumentation is disabled"
|
||||
fi
|
||||
|
||||
while [ $((curr_time - start_time)) -lt $OPT_RUN_TIME ]; do
|
||||
|
||||
disk_space $d > $d/$p-disk-space
|
||||
@@ -946,6 +953,10 @@ collect() {
|
||||
(echo $ts; transactions) >>"$d/$p-transactions" &
|
||||
fi
|
||||
|
||||
if [ $ps_instrumentation_enabled == "yes" ]; then
|
||||
ps_locks_transactions "$d/$p-ps-locks-transactions"
|
||||
fi
|
||||
|
||||
curr_time=$(date +'%s')
|
||||
done
|
||||
log "Loop end: $(date +'TS %s.%N %F %T')"
|
||||
@@ -1083,6 +1094,33 @@ innodb_status() {
|
||||
}
|
||||
}
|
||||
|
||||
ps_locks_transactions() {
|
||||
local outfile=$1
|
||||
|
||||
mysql -e 'select @@performance_schema' | grep "1" &>/dev/null
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
local status="select t.processlist_id, ml.* from performance_schema.metadata_locks ml join performance_schema.threads t on (ml.owner_thread_id=t.thread_id)\G"
|
||||
echo -e "\n$status\n" >> $outfile
|
||||
$CMD_MYSQL $EXT_ARGV -e "$status" >> $outfile
|
||||
|
||||
local status="select t.processlist_id, th.* from performance_schema.table_handles th left join performance_schema.threads t on (th.owner_thread_id=t.thread_id)\G"
|
||||
echo -e "\n$status\n" >> $outfile
|
||||
$CMD_MYSQL $EXT_ARGV -e "$status" >> $outfile
|
||||
|
||||
local status="select t.processlist_id, et.* from performance_schema.events_transactions_current et join performance_schema.threads t using(thread_id)\G"
|
||||
echo -e "\n$status\n" >> $outfile
|
||||
$CMD_MYSQL $EXT_ARGV -e "$status" >> $outfile
|
||||
|
||||
local status="select t.processlist_id, et.* from performance_schema.events_transactions_history_long et join performance_schema.threads t using(thread_id)\G"
|
||||
echo -e "\n$status\n" >> $outfile
|
||||
$CMD_MYSQL $EXT_ARGV -e "$status" >> $outfile
|
||||
else
|
||||
echo "Performance schema is not enabled" >> $outfile
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
# ###########################################################################
|
||||
# End collect package
|
||||
# ###########################################################################
|
||||
|
||||
@@ -102,6 +102,7 @@ collect() {
|
||||
log "Could not find the MySQL error log"
|
||||
fi
|
||||
|
||||
|
||||
# Get a sample of these right away, so we can get these without interaction
|
||||
# with the other commands we're about to run.
|
||||
if [ "${mysql_version}" '>' "5.1" ]; then
|
||||
@@ -191,6 +192,12 @@ collect() {
|
||||
log "Loop start: $(date +'TS %s.%N %F %T')"
|
||||
local start_time=$(date +'%s')
|
||||
local curr_time=$start_time
|
||||
local ps_instrumentation_enabled=$($CMD_MYSQL $EXT_ARGV -e 'SELECT ENABLED FROM performance_schema.setup_instruments WHERE NAME = "transaction";' \
|
||||
| sed "2q;d" | sed 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/')
|
||||
if [ $ps_instrumentation_enabled != "yes" ]; then
|
||||
log "Performance Schema instrumentation is disabled"
|
||||
fi
|
||||
|
||||
while [ $((curr_time - start_time)) -lt $OPT_RUN_TIME ]; do
|
||||
|
||||
# We check the disk, but don't exit, because we need to stop jobs if we
|
||||
@@ -240,6 +247,10 @@ collect() {
|
||||
(echo $ts; transactions) >>"$d/$p-transactions" &
|
||||
fi
|
||||
|
||||
if [ $ps_instrumentation_enabled == "yes" ]; then
|
||||
ps_locks_transactions "$d/$p-ps-locks-transactions"
|
||||
fi
|
||||
|
||||
curr_time=$(date +'%s')
|
||||
done
|
||||
log "Loop end: $(date +'TS %s.%N %F %T')"
|
||||
@@ -389,6 +400,33 @@ innodb_status() {
|
||||
}
|
||||
}
|
||||
|
||||
ps_locks_transactions() {
|
||||
local outfile=$1
|
||||
|
||||
mysql -e 'select @@performance_schema' | grep "1" &>/dev/null
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
local status="select t.processlist_id, ml.* from performance_schema.metadata_locks ml join performance_schema.threads t on (ml.owner_thread_id=t.thread_id)\G"
|
||||
echo -e "\n$status\n" >> $outfile
|
||||
$CMD_MYSQL $EXT_ARGV -e "$status" >> $outfile
|
||||
|
||||
local status="select t.processlist_id, th.* from performance_schema.table_handles th left join performance_schema.threads t on (th.owner_thread_id=t.thread_id)\G"
|
||||
echo -e "\n$status\n" >> $outfile
|
||||
$CMD_MYSQL $EXT_ARGV -e "$status" >> $outfile
|
||||
|
||||
local status="select t.processlist_id, et.* from performance_schema.events_transactions_current et join performance_schema.threads t using(thread_id)\G"
|
||||
echo -e "\n$status\n" >> $outfile
|
||||
$CMD_MYSQL $EXT_ARGV -e "$status" >> $outfile
|
||||
|
||||
local status="select t.processlist_id, et.* from performance_schema.events_transactions_history_long et join performance_schema.threads t using(thread_id)\G"
|
||||
echo -e "\n$status\n" >> $outfile
|
||||
$CMD_MYSQL $EXT_ARGV -e "$status" >> $outfile
|
||||
else
|
||||
echo "Performance schema is not enabled" >> $outfile
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
# ###########################################################################
|
||||
# End collect package
|
||||
# ###########################################################################
|
||||
|
||||
@@ -30,3 +30,6 @@ lower_case_table_names = 0
|
||||
|
||||
# fkc test
|
||||
binlog_format = STATEMENT
|
||||
performance_schema = ON
|
||||
performance-schema-instrument='wait/lock/metadata/sql/mdl=ON'
|
||||
performance-schema-instrument='transaction=ON'
|
||||
|
||||
@@ -8,6 +8,7 @@ BEGIN {
|
||||
|
||||
use strict;
|
||||
use warnings FATAL => 'all';
|
||||
use threads;
|
||||
use English qw(-no_match_vars);
|
||||
use Test::More;
|
||||
use Time::HiRes qw(sleep);
|
||||
@@ -422,6 +423,48 @@ like(
|
||||
"Accepts floating point values as treshold variable"
|
||||
);
|
||||
|
||||
# ###########################################################################
|
||||
# Test report about performance schema transactions in MySQL 5.7+
|
||||
# ###########################################################################
|
||||
|
||||
cleanup();
|
||||
|
||||
SKIP: {
|
||||
|
||||
skip "Only test on mysql 5.7" if ( $sandbox_version lt '5.7' );
|
||||
|
||||
sub start_thread {
|
||||
# this must run in a thread because we need to have an uncommitted transaction
|
||||
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-1642751.sql");
|
||||
}
|
||||
my $thr = threads->create('start_thread', $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 --iterations=1 "
|
||||
. "--run-time=2 --pid $pid_file --defaults-file=$cnf >$log_file 2>&1";
|
||||
system($cmd);
|
||||
sleep 15;
|
||||
PerconaTest::kill_program(pid_file => $pid_file);
|
||||
|
||||
$output = `cat $dest/*-ps-locks-transactions 2>/dev/null`;
|
||||
like(
|
||||
$output,
|
||||
qr/ STATE: ACTIVE/,
|
||||
"MySQL 5.7 ACTIVE transactions"
|
||||
);
|
||||
|
||||
like(
|
||||
$output,
|
||||
qr/ STATE: COMMITTED/,
|
||||
"MySQL 5.7 COMMITTED transactions"
|
||||
);
|
||||
}
|
||||
|
||||
# #############################################################################
|
||||
# Done.
|
||||
|
||||
29
t/pt-stalk/samples/issue-1642751.sql
Normal file
29
t/pt-stalk/samples/issue-1642751.sql
Normal file
@@ -0,0 +1,29 @@
|
||||
/* This enables perfomance schema without a server restart */
|
||||
UPDATE performance_schema.setup_consumers SET enabled='YES' WHERE NAME = 'events_waits_current';
|
||||
|
||||
/* Enable instrumentation */
|
||||
UPDATE performance_schema.setup_consumers SET ENABLED='YES' WHERE NAME LIKE '%events_transactions%';
|
||||
UPDATE performance_schema.setup_consumers SET ENABLED='YES' WHERE NAME LIKE '%events_transactions%';
|
||||
UPDATE performance_schema.setup_instruments SET ENABLED='YES' WHERE NAME = 'wait/lock/metadata/sql/mdl';
|
||||
|
||||
CREATE SCHEMA IF NOT EXISTS test;
|
||||
|
||||
USE test;
|
||||
DROP TABLE IF EXISTS t1;
|
||||
CREATE TABLE t1 (id int) ENGINE=INNODB;
|
||||
|
||||
/* Successfuly finished transaction */
|
||||
SET autocommit=0;
|
||||
START TRANSACTION;
|
||||
INSERT INTO t1 VALUES (CEIL(RAND()*10000));
|
||||
COMMIT;
|
||||
|
||||
/* Ongoing transaction */
|
||||
SET autocommit=0;
|
||||
START TRANSACTION;
|
||||
INSERT INTO t1 VALUES (CEIL(RAND()*10000));
|
||||
/* Wait to let pt-stalk to collect the data and find an ACTIVE transaction */
|
||||
SELECT SLEEP(11);
|
||||
COMMIT;
|
||||
|
||||
DROP DATABASE IF EXISTS test;
|
||||
Reference in New Issue
Block a user