Add RawLogParser.pm and implement --type rawlog in pt-query-digest (Percona 22371).

This commit is contained in:
Daniel Nichter
2012-06-28 15:04:10 -06:00
parent 5c914b6e25
commit 938b9720c1
6 changed files with 339 additions and 1 deletions

52
t/lib/RawLogParser.t Normal file
View File

@@ -0,0 +1,52 @@
#!/usr/bin/perl
BEGIN {
die "The PERCONA_TOOLKIT_BRANCH environment variable is not set.\n"
unless $ENV{PERCONA_TOOLKIT_BRANCH} && -d $ENV{PERCONA_TOOLKIT_BRANCH};
unshift @INC, "$ENV{PERCONA_TOOLKIT_BRANCH}/lib";
};
use strict;
use warnings FATAL => 'all';
use English qw(-no_match_vars);
use Test::More tests => 3;
use RawLogParser;
use PerconaTest;
my $p = new RawLogParser();
my $oktorun = 1;
my $sample = "t/lib/samples/rawlogs/";
test_log_parser(
parser => $p,
file => $sample.'rawlog001.txt',
oktorun => sub { $oktorun = $_[0]; },
result => [
{ pos_in_log => 0,
args => 'SELECT c FROM t WHERE id=1',
bytes => 26,
cmd => 'Query',
Query_time => 0,
},
{ pos_in_log => 27,
args => '/* Hello, world! */ SELECT * FROM t2 LIMIT 1',
bytes => 44,
cmd => 'Query',
Query_time => 0,
}
]
);
is(
$oktorun,
0,
'Sets oktorun'
);
$oktorun = 1;
# #############################################################################
# Done.
# #############################################################################
exit;

View File

@@ -0,0 +1,2 @@
SELECT c FROM t WHERE id=1
/* Hello, world! */ SELECT * FROM t2 LIMIT 1

View File

@@ -0,0 +1,48 @@
#!/usr/bin/env perl
BEGIN {
die "The PERCONA_TOOLKIT_BRANCH environment variable is not set.\n"
unless $ENV{PERCONA_TOOLKIT_BRANCH} && -d $ENV{PERCONA_TOOLKIT_BRANCH};
unshift @INC, "$ENV{PERCONA_TOOLKIT_BRANCH}/lib";
};
use strict;
use warnings FATAL => 'all';
use English qw(-no_match_vars);
use Test::More tests => 2;
use PerconaTest;
# See 101_slowlog_analyses.t or http://code.google.com/p/maatkit/wiki/Testing
shift @INC; # our unshift (above)
shift @INC; # PerconaTest's unshift
require "$trunk/bin/pt-query-digest";
# #############################################################################
# Issue 172: Make mk-query-digest able to read raweral logs
# #############################################################################
my @args = ('--report-format', 'header,query_report,profile', '--type', 'rawlog');
my $sample = "$trunk/t/lib/samples/rawlogs/";
# --help exists so don't run mqd as a module else --help's exit will
# exit this test script.
like(
`$trunk/bin/pt-query-digest --type rawlog rawlog001.txt --help`,
qr/--order-by\s+Query_time:cnt/,
'--order-by defaults to Query_time:cnt for --type rawlog',
);
ok(
no_diff(
sub { pt_query_digest::main(@args, $sample.'rawlog001.txt') },
"t/pt-query-digest/samples/rawlog001.txt"
),
'Analysis for rawlog001',
);
# #############################################################################
# Done.
# #############################################################################
exit;

View File

@@ -0,0 +1,60 @@
# Overall: 2 total, 2 unique, 0 QPS, 0x concurrency ______________________
# Attribute total min max avg 95% stddev median
# ============ ======= ======= ======= ======= ======= ======= =======
# Exec time 0 0 0 0 0 0 0
# Query size 70 26 44 35 44 12.73 35
# Query 1: 0 QPS, 0x concurrency, ID 0xCB5621E548E5497F at byte 0 ________
# This item is included in the report because it matches --limit.
# Scores: Apdex = 1.00 [1.0]*, V/M = 0.00
# Query_time sparkline: | |
# Attribute pct total min max avg 95% stddev median
# ============ === ======= ======= ======= ======= ======= ======= =======
# Count 50 1
# Exec time 0 0 0 0 0 0 0 0
# Query size 37 26 26 26 26 26 0 26
# Query_time distribution
# 1us
# 10us
# 100us
# 1ms
# 10ms
# 100ms
# 1s
# 10s+
# Tables
# SHOW TABLE STATUS LIKE 't'\G
# SHOW CREATE TABLE `t`\G
# EXPLAIN /*!50100 PARTITIONS*/
SELECT c FROM t WHERE id=1\G
# Query 2: 0 QPS, 0x concurrency, ID 0x774B2B0B59EBAC2C at byte 27 _______
# This item is included in the report because it matches --limit.
# Scores: Apdex = 1.00 [1.0]*, V/M = 0.00
# Query_time sparkline: | |
# Attribute pct total min max avg 95% stddev median
# ============ === ======= ======= ======= ======= ======= ======= =======
# Count 50 1
# Exec time 0 0 0 0 0 0 0 0
# Query size 62 44 44 44 44 44 0 44
# Query_time distribution
# 1us
# 10us
# 100us
# 1ms
# 10ms
# 100ms
# 1s
# 10s+
# Tables
# SHOW TABLE STATUS LIKE 't2'\G
# SHOW CREATE TABLE `t2`\G
# EXPLAIN /*!50100 PARTITIONS*/
/* Hello, world! */ SELECT * FROM t2 LIMIT 1\G
# Profile
# Rank Query ID Response time Calls R/Call Apdx V/M Item
# ==== ================== ============= ===== ====== ==== ===== =========
# 1 0xCB5621E548E5497F 0.0000 0.0% 1 0.0000 1.00 0.00 SELECT t
# 2 0x774B2B0B59EBAC2C 0.0000 0.0% 1 0.0000 1.00 0.00 SELECT t?