Merge lp:~percona-toolkit-dev/percona-toolkit/fix-1160918-restore-show-all into lp:percona-toolkit/2.2

Proposed by Brian Fraser
Status: Merged
Approved by: Daniel Nichter
Approved revision: 572
Merged at revision: 575
Proposed branch: lp:~percona-toolkit-dev/percona-toolkit/fix-1160918-restore-show-all
Merge into: lp:percona-toolkit/2.2
Diff against target: 323 lines (+63/-20)
10 files modified
bin/pt-query-digest (+43/-11)
lib/QueryReportFormatter.pm (+12/-1)
t/lib/samples/QueryReportFormatter/report012.txt (+1/-1)
t/lib/samples/QueryReportFormatter/report013.txt (+1/-1)
t/lib/samples/QueryReportFormatter/report014.txt (+1/-1)
t/lib/samples/QueryReportFormatter/report015.txt (+1/-1)
t/pt-query-digest/samples/slow042-show-all-host.txt (+1/-1)
t/pt-query-digest/samples/slow053.txt (+1/-1)
t/pt-query-digest/samples/slow054.txt (+1/-1)
t/pt-query-digest/samples/tcpdump033.txt (+1/-1)
To merge this branch: bzr merge lp:~percona-toolkit-dev/percona-toolkit/fix-1160918-restore-show-all
Reviewer Review Type Date Requested Status
Daniel Nichter Approve
Review via email: mp+158685@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Daniel Nichter (daniel-nichter) wrote :

I see this has my null_event change. I can't recall why I implemented that--maybe for pt-upgrade? In any case, I don't think it's well-tested, but I also don't think it will be disruptive because I do recall specifically making it backwards-compatible, i.e. transparent to origina code. So this branch should be ok.

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 2013-03-20 17:53:36 +0000
3+++ bin/pt-query-digest 2013-04-12 17:46:27 +0000
4@@ -81,6 +81,7 @@
5 # ###########################################################################
6 {
7 package Lmo::Utils;
8+
9 use strict;
10 use warnings qw( FATAL all );
11 require Exporter;
12@@ -88,7 +89,12 @@
13
14 BEGIN {
15 @ISA = qw(Exporter);
16- @EXPORT = @EXPORT_OK = qw(_install_coderef _unimport_coderefs _glob_for _stash_for);
17+ @EXPORT = @EXPORT_OK = qw(
18+ _install_coderef
19+ _unimport_coderefs
20+ _glob_for
21+ _stash_for
22+ );
23 }
24
25 {
26@@ -272,7 +278,6 @@
27 return Lmo::Meta->new(class => $class);
28 }
29
30-
31 1;
32 }
33 # ###########################################################################
34@@ -3789,6 +3794,7 @@
35 sessions => {},
36 o => $args{o},
37 fake_thread_id => 2**32, # see _make_event()
38+ null_event => $args{null_event},
39 };
40 PTDEBUG && $self->{server} && _d('Watching only server', $self->{server});
41 return bless $self, $class;
42@@ -3809,7 +3815,7 @@
43 $server .= ":$self->{port}";
44 if ( $src_host ne $server && $dst_host ne $server ) {
45 PTDEBUG && _d('Packet is not to or from', $server);
46- return;
47+ return $self->{null_event};
48 }
49 }
50
51@@ -3825,7 +3831,7 @@
52 }
53 else {
54 PTDEBUG && _d('Packet is not to or from a MySQL server');
55- return;
56+ return $self->{null_event};
57 }
58 PTDEBUG && _d('Client', $client);
59
60@@ -3843,7 +3849,7 @@
61 else {
62 PTDEBUG && _d('Ignoring mid-stream', $packet_from, 'data,',
63 'packetno', $packetno);
64- return;
65+ return $self->{null_event};
66 }
67
68 $self->{sessions}->{$client} = {
69@@ -3886,7 +3892,7 @@
70 delete $self->{sessions}->{$session->{client}};
71 return $event;
72 }
73- return;
74+ return $self->{null_event};
75 }
76
77 if ( $session->{compress} ) {
78@@ -3912,7 +3918,7 @@
79 PTDEBUG && _d('remove_mysql_header() failed; failing session');
80 $session->{EVAL_ERROR} = $EVAL_ERROR;
81 $self->fail_session($session, 'remove_mysql_header() failed');
82- return;
83+ return $self->{null_event};
84 }
85 }
86
87@@ -3927,7 +3933,7 @@
88 $self->_delete_buff($session);
89 }
90 else {
91- return; # waiting for more data; buff_left was reported earlier
92+ return $self->{null_event}; # waiting for more data; buff_left was reported earlier
93 }
94 }
95 elsif ( $packet->{mysql_data_len} > ($packet->{data_len} - 4) ) {
96@@ -3948,7 +3954,7 @@
97
98 PTDEBUG && _d('Data not complete; expecting',
99 $session->{buff_left}, 'more bytes');
100- return;
101+ return $self->{null_event};
102 }
103
104 if ( $session->{cmd} && ($session->{state} || '') eq 'awaiting_reply' ) {
105@@ -3971,7 +3977,7 @@
106 }
107
108 $args{stats}->{events_parsed}++ if $args{stats};
109- return $event;
110+ return $event || $self->{null_event};
111 }
112
113 sub _packet_from_server {
114@@ -6519,6 +6525,12 @@
115 default => sub { [qw(pct total min max avg 95% stddev median)] },
116 );
117
118+has show_all => (
119+ is => 'ro',
120+ isa => 'HashRef',
121+ default => sub { {} },
122+);
123+
124 has ReportFormatter => (
125 is => 'ro',
126 isa => 'ReportFormatter',
127@@ -7398,11 +7410,13 @@
128
129 sub format_string_list {
130 my ( $self, $attrib, $vals, $class_cnt ) = @_;
131-
132+
133 if ( !exists $vals->{unq} ) {
134 return ($vals->{cnt});
135 }
136
137+ my $show_all = $self->show_all();
138+
139 my $cnt_for = $vals->{unq};
140 if ( 1 == keys %$cnt_for ) {
141 my ($str) = keys %$cnt_for;
142@@ -7427,6 +7441,9 @@
143 }
144 my $p = percentage_of($cnt_for->{$str}, $class_cnt);
145 $print_str .= " ($cnt_for->{$str}/$p%)";
146+ if ( !$show_all->{$attrib} ) {
147+ last if (length $line) + (length $print_str) > LINE_LENGTH - 27;
148+ }
149 $line .= "$print_str, ";
150 $i++;
151 }
152@@ -13749,6 +13766,8 @@
153 my @groupby = @{$args{groupby}};
154 my @orderby = @{$args{orderby}};
155
156+ my $show_all = $o->get('show-all');
157+
158 for my $i ( 0..$#groupby ) {
159 if ( $o->get('report') || $qv || $qh ) {
160 $eas->[$i]->calculate_statistical_metrics();
161@@ -13799,6 +13818,7 @@
162 OptionParser => $args{OptionParser},
163 QueryParser => $args{QueryParser},
164 Quoter => $args{Quoter},
165+ show_all => $show_all,
166 );
167
168 $qrf->print_reports(
169@@ -15502,6 +15522,18 @@
170
171 The tool prints a warning and continues if a variable cannot be set.
172
173+=item --show-all
174+
175+type: Hash
176+
177+Show all values for these attributes.
178+
179+By default pt-query-digest only shows as many of an attribute's value that
180+fit on a single line. This option allows you to specify attributes for which
181+all values will be shown (line width is ignored). This only works for
182+attributes with string values like user, host, db, etc. Multiple attributes
183+can be specified, comma-separated.
184+
185 =item --since
186
187 type: string
188
189=== modified file 'lib/QueryReportFormatter.pm'
190--- lib/QueryReportFormatter.pm 2013-02-25 16:10:03 +0000
191+++ lib/QueryReportFormatter.pm 2013-04-12 17:46:27 +0000
192@@ -84,6 +84,12 @@
193 default => sub { [qw(pct total min max avg 95% stddev median)] },
194 );
195
196+has show_all => (
197+ is => 'ro',
198+ isa => 'HashRef',
199+ default => sub { {} },
200+);
201+
202 has ReportFormatter => (
203 is => 'ro',
204 isa => 'ReportFormatter',
205@@ -1114,13 +1120,15 @@
206 # Does pretty-printing for lists of strings like users, hosts, db.
207 sub format_string_list {
208 my ( $self, $attrib, $vals, $class_cnt ) = @_;
209-
210+
211 # Only class result values have unq. So if unq doesn't exist,
212 # then we've been given global values.
213 if ( !exists $vals->{unq} ) {
214 return ($vals->{cnt});
215 }
216
217+ my $show_all = $self->show_all();
218+
219 my $cnt_for = $vals->{unq};
220 if ( 1 == keys %$cnt_for ) {
221 my ($str) = keys %$cnt_for;
222@@ -1146,6 +1154,9 @@
223 }
224 my $p = percentage_of($cnt_for->{$str}, $class_cnt);
225 $print_str .= " ($cnt_for->{$str}/$p%)";
226+ if ( !$show_all->{$attrib} ) {
227+ last if (length $line) + (length $print_str) > LINE_LENGTH - 27;
228+ }
229 $line .= "$print_str, ";
230 $i++;
231 }
232
233=== modified file 't/lib/samples/QueryReportFormatter/report012.txt'
234--- t/lib/samples/QueryReportFormatter/report012.txt 2013-02-25 16:10:03 +0000
235+++ t/lib/samples/QueryReportFormatter/report012.txt 2013-04-12 17:46:27 +0000
236@@ -7,4 +7,4 @@
237 # Count 100 3
238 # Exec time 100 6s 1s 3s 2s 3s 780ms 2s
239 # String:
240-# foo Hi. I'm a... (1/33%), Me too! I'... (1/33%), Number 3 l... (1/33%)
241+# foo Hi. I'm a... (1/33%), Me too! I'... (1/33%)... 1 more
242
243=== modified file 't/lib/samples/QueryReportFormatter/report013.txt'
244--- t/lib/samples/QueryReportFormatter/report013.txt 2013-02-25 16:10:03 +0000
245+++ t/lib/samples/QueryReportFormatter/report013.txt 2013-04-12 17:46:27 +0000
246@@ -5,4 +5,4 @@
247 # Count 100 2
248 # Exec time 100 16s 8s 8s 8s 8s 0 8s
249 # String:
250-# Hosts 123.123.123.456 (1/50%), 123.123.123.789 (1/50%)
251+# Hosts 123.123.123.456 (1/50%)... 1 more
252
253=== modified file 't/lib/samples/QueryReportFormatter/report014.txt'
254--- t/lib/samples/QueryReportFormatter/report014.txt 2013-02-25 16:10:03 +0000
255+++ t/lib/samples/QueryReportFormatter/report014.txt 2013-04-12 17:46:27 +0000
256@@ -5,4 +5,4 @@
257 # Count 100 3
258 # Exec time 100 24s 8s 8s 8s 8s 0 8s
259 # String:
260-# Hosts 123.123.123.456 (1/33%), 123.123.123.789 (1/33%), 123.123.123.999 (1/33%)
261+# Hosts 123.123.123.456 (1/33%)... 2 more
262
263=== modified file 't/lib/samples/QueryReportFormatter/report015.txt'
264--- t/lib/samples/QueryReportFormatter/report015.txt 2013-01-11 16:45:20 +0000
265+++ t/lib/samples/QueryReportFormatter/report015.txt 2013-04-12 17:46:27 +0000
266@@ -5,4 +5,4 @@
267 # Count 100 3
268 # Exec time 100 24s 8s 8s 8s 8s 0 8s
269 # String:
270-# Hosts 123.123.123.456 (1/33%), 123.123.123.789 (1/33%), 123.123.123.999 (1/33%)
271+# Hosts 123.123.123.456 (1/33%)... 2 more
272
273=== modified file 't/pt-query-digest/samples/slow042-show-all-host.txt'
274--- t/pt-query-digest/samples/slow042-show-all-host.txt 2013-01-11 16:45:20 +0000
275+++ t/pt-query-digest/samples/slow042-show-all-host.txt 2013-04-12 17:46:27 +0000
276@@ -14,7 +14,7 @@
277 # Rows read 100 690 230 230 230 230 0 230
278 # Query size 100 31 10 11 10.33 10.84 0.47 9.83
279 # String:
280-# Hosts 123.123.123.121 (1/33%), 123.123.123.122 (1/33%), 123.123.123.123 (1/33%)
281+# Hosts 123.123.123.121 (1/33%)... 2 more
282 # Users chessguest
283 # Query_time distribution
284 # 1us
285
286=== modified file 't/pt-query-digest/samples/slow053.txt'
287--- t/pt-query-digest/samples/slow053.txt 2013-02-25 16:10:03 +0000
288+++ t/pt-query-digest/samples/slow053.txt 2013-04-12 17:46:27 +0000
289@@ -72,7 +72,7 @@
290 # Rows examine 0 0 0 0 0 0 0 0
291 # Query size 45 140 28 28 28 28 0 28
292 # String:
293-# arg crc 108 (1/20%), 306 (1/20%), 353 (1/20%), 558 (1/20%), 887 (1/20%)
294+# arg crc 108 (1/20%), 306 (1/20%), 353 (1/20%)... 2 more
295 # Query_time distribution
296 # 1us
297 # 10us ################################################################
298
299=== modified file 't/pt-query-digest/samples/slow054.txt'
300--- t/pt-query-digest/samples/slow054.txt 2013-02-25 16:10:03 +0000
301+++ t/pt-query-digest/samples/slow054.txt 2013-04-12 17:46:27 +0000
302@@ -12,7 +12,7 @@
303 # Rows examine 0 0 0 0 0 0 0 0
304 # Query size 100 224 28 28 28 28 0 28
305 # String:
306-# InnoDB trxID 101 (1/12%), 102 (1/12%), 103 (1/12%), 104 (1/12%), 105 (1/12%), 106 (1/12%), A07 (1/12%), A08 (1/12%)
307+# InnoDB trxID 101 (1/12%), 102 (1/12%), 103 (1/12%)... 5 more
308 # Query_time distribution
309 # 1us
310 # 10us ################################################################
311
312=== modified file 't/pt-query-digest/samples/tcpdump033.txt'
313--- t/pt-query-digest/samples/tcpdump033.txt 2013-02-25 16:10:03 +0000
314+++ t/pt-query-digest/samples/tcpdump033.txt 2013-04-12 17:46:27 +0000
315@@ -56,7 +56,7 @@
316 # Warning coun 0 0 0 0 0 0 0 0
317 # String:
318 # Hosts 127.0.0.1
319-# Statement id 2 (1/20%), 3 (1/20%), 4 (1/20%), 5 (1/20%), 6 (1/20%)
320+# Statement id 2 (1/20%), 3 (1/20%), 4 (1/20%), 5 (1/20%)... 1 more
321 # Query_time distribution
322 # 1us
323 # 10us

Subscribers

People subscribed via source and target branches