Merge lp:~percona-toolkit-dev/percona-toolkit/raw-log-parser-percona-22371 into lp:percona-toolkit/2.1

Proposed by Brian Fraser
Status: Merged
Approved by: Daniel Nichter
Approved revision: 303
Merged at revision: 409
Proposed branch: lp:~percona-toolkit-dev/percona-toolkit/raw-log-parser-percona-22371
Merge into: lp:percona-toolkit/2.1
Diff against target: 390 lines (+339/-1)
6 files modified
bin/pt-query-digest (+82/-1)
lib/RawLogParser.pm (+95/-0)
t/lib/RawLogParser.t (+52/-0)
t/lib/samples/rawlogs/rawlog001.txt (+2/-0)
t/pt-query-digest/rawlog_analyses.t (+48/-0)
t/pt-query-digest/samples/rawlog001.txt (+60/-0)
To merge this branch: bzr merge lp:~percona-toolkit-dev/percona-toolkit/raw-log-parser-percona-22371
Reviewer Review Type Date Requested Status
Brian Fraser (community) Approve
Daniel Nichter Approve
Review via email: mp+127295@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Daniel Nichter (daniel-nichter) wrote :

Create a quick blueprint and target to 2.1.6.

Revision history for this message
Daniel Nichter (daniel-nichter) :
review: Approve
Revision history for this message
Brian Fraser (fraserbn) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/pt-query-digest'
2--- bin/pt-query-digest 2012-09-24 19:24:36 +0000
3+++ bin/pt-query-digest 2012-10-01 14:30:45 +0000
4@@ -9757,6 +9757,86 @@
5 # ###########################################################################
6
7 # ###########################################################################
8+# RawLogParser package
9+# This package is a copy without comments from the original. The original
10+# with comments and its test file can be found in the Bazaar repository at,
11+# lib/RawLogParser.pm
12+# t/lib/RawLogParser.t
13+# See https://launchpad.net/percona-toolkit for more information.
14+# ###########################################################################
15+{
16+package RawLogParser;
17+
18+use strict;
19+use warnings FATAL => 'all';
20+use English qw(-no_match_vars);
21+use constant PTDEBUG => $ENV{PTDEBUG} || 0;
22+
23+use Data::Dumper;
24+$Data::Dumper::Indent = 1;
25+$Data::Dumper::Sortkeys = 1;
26+$Data::Dumper::Quotekeys = 0;
27+
28+sub new {
29+ my ( $class ) = @_;
30+ my $self = {
31+ };
32+ return bless $self, $class;
33+}
34+
35+sub parse_event {
36+ my ( $self, %args ) = @_;
37+ my @required_args = qw(next_event tell);
38+ foreach my $arg ( @required_args ) {
39+ die "I need a $arg argument" unless $args{$arg};
40+ }
41+ my ($next_event, $tell) = @args{@required_args};
42+
43+ my $line;
44+ my $pos_in_log = $tell->();
45+ LINE:
46+ while ( defined($line = $next_event->()) ) {
47+ PTDEBUG && _d($line);
48+ chomp($line);
49+ my @properties = (
50+ 'pos_in_log', $pos_in_log,
51+ 'cmd', 'Query',
52+ 'bytes', length($line),
53+ 'Query_time', 0,
54+ 'arg', $line,
55+ );
56+
57+ $pos_in_log = $tell->();
58+
59+ PTDEBUG && _d('Properties of event:', Dumper(\@properties));
60+ my $event = { @properties };
61+ if ( $args{stats} ) {
62+ $args{stats}->{events_read}++;
63+ $args{stats}->{events_parsed}++;
64+ }
65+
66+ return $event;
67+ }
68+
69+ $args{oktorun}->(0) if $args{oktorun};
70+ return;
71+}
72+
73+sub _d {
74+ my ($package, undef, $line) = caller 0;
75+ @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
76+ map { defined $_ ? $_ : 'undef' }
77+ @_;
78+ print STDERR "# $package:$line $PID ", join(' ', @_), "\n";
79+}
80+
81+1;
82+}
83+# ###########################################################################
84+# End RawLogParser package
85+# ###########################################################################
86+
87+# ###########################################################################
88 # ProtocolParser package
89 # This package is a copy without comments from the original. The original
90 # with comments and its test file can be found in the Bazaar repository at,
91@@ -13227,7 +13307,7 @@
92 my $review_dsn = $o->get('review');
93 my @groupby = @{$o->get('group-by')};
94 my @orderby;
95- if ( (grep { $_ eq 'genlog' || $_ eq 'GeneralLogParser' } @{$o->get('type')})
96+ if ( (grep { $_ =~ m/genlog|GeneralLogParser|rawlog|RawLogParser/ } @{$o->get('type')})
97 && !$o->got('order-by') ) {
98 @orderby = 'Query_time:cnt';
99 }
100@@ -13668,6 +13748,7 @@
101 'MemcachedEvent'],
102 http => ['TcpdumpParser','HTTPProtocolParser'],
103 pglog => ['PgLogParser'],
104+ rawlog => ['RawLogParser'],
105 );
106 my $type = $o->get('type');
107 $type = $alias_for{$type->[0]} if $alias_for{$type->[0]};
108
109=== added file 'lib/RawLogParser.pm'
110--- lib/RawLogParser.pm 1970-01-01 00:00:00 +0000
111+++ lib/RawLogParser.pm 2012-10-01 14:30:45 +0000
112@@ -0,0 +1,95 @@
113+# This program is copyright 2012 Percona Inc.
114+# Feedback and improvements are welcome.
115+#
116+# THIS PROGRAM IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
117+# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
118+# MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
119+#
120+# This program is free software; you can redistribute it and/or modify it under
121+# the terms of the GNU General Public License as published by the Free Software
122+# Foundation, version 2; OR the Perl Artistic License. On UNIX and similar
123+# systems, you can issue `man perlgpl' or `man perlartistic' to read these
124+# licenses.
125+#
126+# You should have received a copy of the GNU General Public License along with
127+# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
128+# Place, Suite 330, Boston, MA 02111-1307 USA.
129+# ###########################################################################
130+# RawLogParser package
131+# ###########################################################################
132+{
133+# Package: RawLogParser
134+# RawLogParser parses logs with nothing but one query per line.
135+package RawLogParser;
136+
137+use strict;
138+use warnings FATAL => 'all';
139+use English qw(-no_match_vars);
140+use constant PTDEBUG => $ENV{PTDEBUG} || 0;
141+
142+use Data::Dumper;
143+$Data::Dumper::Indent = 1;
144+$Data::Dumper::Sortkeys = 1;
145+$Data::Dumper::Quotekeys = 0;
146+
147+sub new {
148+ my ( $class ) = @_;
149+ my $self = {
150+ };
151+ return bless $self, $class;
152+}
153+
154+sub parse_event {
155+ my ( $self, %args ) = @_;
156+ my @required_args = qw(next_event tell);
157+ foreach my $arg ( @required_args ) {
158+ die "I need a $arg argument" unless $args{$arg};
159+ }
160+ my ($next_event, $tell) = @args{@required_args};
161+
162+ my $line;
163+ my $pos_in_log = $tell->();
164+ LINE:
165+ while ( defined($line = $next_event->()) ) {
166+ PTDEBUG && _d($line);
167+ chomp($line);
168+ my @properties = (
169+ 'pos_in_log', $pos_in_log,
170+ 'cmd', 'Query',
171+ 'bytes', length($line),
172+ 'Query_time', 0,
173+ 'arg', $line,
174+ );
175+
176+ $pos_in_log = $tell->();
177+
178+ # Don't dump $event; want to see full dump of all properties,
179+ # and after it's been cast into a hash, duplicated keys will
180+ # be gone.
181+ PTDEBUG && _d('Properties of event:', Dumper(\@properties));
182+ my $event = { @properties };
183+ if ( $args{stats} ) {
184+ $args{stats}->{events_read}++;
185+ $args{stats}->{events_parsed}++;
186+ }
187+
188+ return $event;
189+ }
190+
191+ $args{oktorun}->(0) if $args{oktorun};
192+ return;
193+}
194+
195+sub _d {
196+ my ($package, undef, $line) = caller 0;
197+ @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
198+ map { defined $_ ? $_ : 'undef' }
199+ @_;
200+ print STDERR "# $package:$line $PID ", join(' ', @_), "\n";
201+}
202+
203+1;
204+}
205+# ###########################################################################
206+# End RawLogParser package
207+# ###########################################################################
208
209=== added file 't/lib/RawLogParser.t'
210--- t/lib/RawLogParser.t 1970-01-01 00:00:00 +0000
211+++ t/lib/RawLogParser.t 2012-10-01 14:30:45 +0000
212@@ -0,0 +1,52 @@
213+#!/usr/bin/perl
214+
215+BEGIN {
216+ die "The PERCONA_TOOLKIT_BRANCH environment variable is not set.\n"
217+ unless $ENV{PERCONA_TOOLKIT_BRANCH} && -d $ENV{PERCONA_TOOLKIT_BRANCH};
218+ unshift @INC, "$ENV{PERCONA_TOOLKIT_BRANCH}/lib";
219+};
220+
221+use strict;
222+use warnings FATAL => 'all';
223+use English qw(-no_match_vars);
224+use Test::More tests => 3;
225+
226+use RawLogParser;
227+use PerconaTest;
228+
229+my $p = new RawLogParser();
230+
231+my $oktorun = 1;
232+my $sample = "t/lib/samples/rawlogs/";
233+
234+test_log_parser(
235+ parser => $p,
236+ file => $sample.'rawlog001.txt',
237+ oktorun => sub { $oktorun = $_[0]; },
238+ result => [
239+ { pos_in_log => 0,
240+ args => 'SELECT c FROM t WHERE id=1',
241+ bytes => 26,
242+ cmd => 'Query',
243+ Query_time => 0,
244+ },
245+ { pos_in_log => 27,
246+ args => '/* Hello, world! */ SELECT * FROM t2 LIMIT 1',
247+ bytes => 44,
248+ cmd => 'Query',
249+ Query_time => 0,
250+ }
251+ ]
252+);
253+
254+is(
255+ $oktorun,
256+ 0,
257+ 'Sets oktorun'
258+);
259+$oktorun = 1;
260+
261+# #############################################################################
262+# Done.
263+# #############################################################################
264+exit;
265
266=== added directory 't/lib/samples/rawlogs'
267=== added file 't/lib/samples/rawlogs/rawlog001.txt'
268--- t/lib/samples/rawlogs/rawlog001.txt 1970-01-01 00:00:00 +0000
269+++ t/lib/samples/rawlogs/rawlog001.txt 2012-10-01 14:30:45 +0000
270@@ -0,0 +1,2 @@
271+SELECT c FROM t WHERE id=1
272+/* Hello, world! */ SELECT * FROM t2 LIMIT 1
273
274=== added file 't/pt-query-digest/rawlog_analyses.t'
275--- t/pt-query-digest/rawlog_analyses.t 1970-01-01 00:00:00 +0000
276+++ t/pt-query-digest/rawlog_analyses.t 2012-10-01 14:30:45 +0000
277@@ -0,0 +1,48 @@
278+#!/usr/bin/env perl
279+
280+BEGIN {
281+ die "The PERCONA_TOOLKIT_BRANCH environment variable is not set.\n"
282+ unless $ENV{PERCONA_TOOLKIT_BRANCH} && -d $ENV{PERCONA_TOOLKIT_BRANCH};
283+ unshift @INC, "$ENV{PERCONA_TOOLKIT_BRANCH}/lib";
284+};
285+
286+use strict;
287+use warnings FATAL => 'all';
288+use English qw(-no_match_vars);
289+use Test::More tests => 2;
290+
291+use PerconaTest;
292+
293+# See 101_slowlog_analyses.t or http://code.google.com/p/maatkit/wiki/Testing
294+shift @INC; # our unshift (above)
295+shift @INC; # PerconaTest's unshift
296+
297+require "$trunk/bin/pt-query-digest";
298+
299+# #############################################################################
300+# Issue 172: Make mk-query-digest able to read raweral logs
301+# #############################################################################
302+
303+my @args = ('--report-format', 'header,query_report,profile', '--type', 'rawlog');
304+my $sample = "$trunk/t/lib/samples/rawlogs/";
305+
306+# --help exists so don't run mqd as a module else --help's exit will
307+# exit this test script.
308+like(
309+ `$trunk/bin/pt-query-digest --type rawlog rawlog001.txt --help`,
310+ qr/--order-by\s+Query_time:cnt/,
311+ '--order-by defaults to Query_time:cnt for --type rawlog',
312+);
313+
314+ok(
315+ no_diff(
316+ sub { pt_query_digest::main(@args, $sample.'rawlog001.txt') },
317+ "t/pt-query-digest/samples/rawlog001.txt"
318+ ),
319+ 'Analysis for rawlog001',
320+);
321+
322+# #############################################################################
323+# Done.
324+# #############################################################################
325+exit;
326
327=== added file 't/pt-query-digest/samples/rawlog001.txt'
328--- t/pt-query-digest/samples/rawlog001.txt 1970-01-01 00:00:00 +0000
329+++ t/pt-query-digest/samples/rawlog001.txt 2012-10-01 14:30:45 +0000
330@@ -0,0 +1,60 @@
331+
332+# Overall: 2 total, 2 unique, 0 QPS, 0x concurrency ______________________
333+# Attribute total min max avg 95% stddev median
334+# ============ ======= ======= ======= ======= ======= ======= =======
335+# Exec time 0 0 0 0 0 0 0
336+# Query size 70 26 44 35 44 12.73 35
337+
338+# Query 1: 0 QPS, 0x concurrency, ID 0xCB5621E548E5497F at byte 0 ________
339+# This item is included in the report because it matches --limit.
340+# Scores: Apdex = 1.00 [1.0]*, V/M = 0.00
341+# Query_time sparkline: | |
342+# Attribute pct total min max avg 95% stddev median
343+# ============ === ======= ======= ======= ======= ======= ======= =======
344+# Count 50 1
345+# Exec time 0 0 0 0 0 0 0 0
346+# Query size 37 26 26 26 26 26 0 26
347+# Query_time distribution
348+# 1us
349+# 10us
350+# 100us
351+# 1ms
352+# 10ms
353+# 100ms
354+# 1s
355+# 10s+
356+# Tables
357+# SHOW TABLE STATUS LIKE 't'\G
358+# SHOW CREATE TABLE `t`\G
359+# EXPLAIN /*!50100 PARTITIONS*/
360+SELECT c FROM t WHERE id=1\G
361+
362+# Query 2: 0 QPS, 0x concurrency, ID 0x774B2B0B59EBAC2C at byte 27 _______
363+# This item is included in the report because it matches --limit.
364+# Scores: Apdex = 1.00 [1.0]*, V/M = 0.00
365+# Query_time sparkline: | |
366+# Attribute pct total min max avg 95% stddev median
367+# ============ === ======= ======= ======= ======= ======= ======= =======
368+# Count 50 1
369+# Exec time 0 0 0 0 0 0 0 0
370+# Query size 62 44 44 44 44 44 0 44
371+# Query_time distribution
372+# 1us
373+# 10us
374+# 100us
375+# 1ms
376+# 10ms
377+# 100ms
378+# 1s
379+# 10s+
380+# Tables
381+# SHOW TABLE STATUS LIKE 't2'\G
382+# SHOW CREATE TABLE `t2`\G
383+# EXPLAIN /*!50100 PARTITIONS*/
384+/* Hello, world! */ SELECT * FROM t2 LIMIT 1\G
385+
386+# Profile
387+# Rank Query ID Response time Calls R/Call Apdx V/M Item
388+# ==== ================== ============= ===== ====== ==== ===== =========
389+# 1 0xCB5621E548E5497F 0.0000 0.0% 1 0.0000 1.00 0.00 SELECT t
390+# 2 0x774B2B0B59EBAC2C 0.0000 0.0% 1 0.0000 1.00 0.00 SELECT t?

Subscribers

People subscribed via source and target branches