From 1dcc6904f3ef40888821c3a63f821ccbb8c2da6a Mon Sep 17 00:00:00 2001 From: Brian Fraser Date: Mon, 8 Apr 2013 09:53:52 -0300 Subject: [PATCH] pqd: Restore the --show-all option --- bin/pt-query-digest | 54 +++++++++++++++---- lib/QueryReportFormatter.pm | 13 ++++- .../QueryReportFormatter/report012.txt | 2 +- .../QueryReportFormatter/report013.txt | 2 +- .../QueryReportFormatter/report014.txt | 2 +- .../QueryReportFormatter/report015.txt | 2 +- .../samples/slow042-show-all-host.txt | 2 +- t/pt-query-digest/samples/slow053.txt | 2 +- t/pt-query-digest/samples/slow054.txt | 2 +- t/pt-query-digest/samples/tcpdump033.txt | 2 +- 10 files changed, 63 insertions(+), 20 deletions(-) diff --git a/bin/pt-query-digest b/bin/pt-query-digest index 896b1f95..469203e1 100755 --- a/bin/pt-query-digest +++ b/bin/pt-query-digest @@ -81,6 +81,7 @@ our $VERSION = '2.2.1'; # ########################################################################### { package Lmo::Utils; + use strict; use warnings qw( FATAL all ); require Exporter; @@ -88,7 +89,12 @@ our (@ISA, @EXPORT, @EXPORT_OK); BEGIN { @ISA = qw(Exporter); - @EXPORT = @EXPORT_OK = qw(_install_coderef _unimport_coderefs _glob_for _stash_for); + @EXPORT = @EXPORT_OK = qw( + _install_coderef + _unimport_coderefs + _glob_for + _stash_for + ); } { @@ -272,7 +278,6 @@ sub meta { return Lmo::Meta->new(class => $class); } - 1; } # ########################################################################### @@ -3789,6 +3794,7 @@ sub new { sessions => {}, o => $args{o}, fake_thread_id => 2**32, # see _make_event() + null_event => $args{null_event}, }; PTDEBUG && $self->{server} && _d('Watching only server', $self->{server}); return bless $self, $class; @@ -3809,7 +3815,7 @@ sub parse_event { $server .= ":$self->{port}"; if ( $src_host ne $server && $dst_host ne $server ) { PTDEBUG && _d('Packet is not to or from', $server); - return; + return $self->{null_event}; } } @@ -3825,7 +3831,7 @@ sub parse_event { } else { PTDEBUG && _d('Packet is not to or from a MySQL server'); - return; + return $self->{null_event}; } PTDEBUG && _d('Client', $client); @@ -3843,7 +3849,7 @@ sub parse_event { else { PTDEBUG && _d('Ignoring mid-stream', $packet_from, 'data,', 'packetno', $packetno); - return; + return $self->{null_event}; } $self->{sessions}->{$client} = { @@ -3886,7 +3892,7 @@ sub parse_event { delete $self->{sessions}->{$session->{client}}; return $event; } - return; + return $self->{null_event}; } if ( $session->{compress} ) { @@ -3912,7 +3918,7 @@ sub parse_event { PTDEBUG && _d('remove_mysql_header() failed; failing session'); $session->{EVAL_ERROR} = $EVAL_ERROR; $self->fail_session($session, 'remove_mysql_header() failed'); - return; + return $self->{null_event}; } } @@ -3927,7 +3933,7 @@ sub parse_event { $self->_delete_buff($session); } else { - return; # waiting for more data; buff_left was reported earlier + return $self->{null_event}; # waiting for more data; buff_left was reported earlier } } elsif ( $packet->{mysql_data_len} > ($packet->{data_len} - 4) ) { @@ -3948,7 +3954,7 @@ sub parse_event { PTDEBUG && _d('Data not complete; expecting', $session->{buff_left}, 'more bytes'); - return; + return $self->{null_event}; } if ( $session->{cmd} && ($session->{state} || '') eq 'awaiting_reply' ) { @@ -3971,7 +3977,7 @@ sub parse_event { } $args{stats}->{events_parsed}++ if $args{stats}; - return $event; + return $event || $self->{null_event}; } sub _packet_from_server { @@ -6519,6 +6525,12 @@ has event_headers => ( default => sub { [qw(pct total min max avg 95% stddev median)] }, ); +has show_all => ( + is => 'ro', + isa => 'HashRef', + default => sub { {} }, +); + has ReportFormatter => ( is => 'ro', isa => 'ReportFormatter', @@ -7398,11 +7410,13 @@ sub bool_percents { sub format_string_list { my ( $self, $attrib, $vals, $class_cnt ) = @_; - + if ( !exists $vals->{unq} ) { return ($vals->{cnt}); } + my $show_all = $self->show_all(); + my $cnt_for = $vals->{unq}; if ( 1 == keys %$cnt_for ) { my ($str) = keys %$cnt_for; @@ -7427,6 +7441,9 @@ sub format_string_list { } my $p = percentage_of($cnt_for->{$str}, $class_cnt); $print_str .= " ($cnt_for->{$str}/$p%)"; + if ( !$show_all->{$attrib} ) { + last if (length $line) + (length $print_str) > LINE_LENGTH - 27; + } $line .= "$print_str, "; $i++; } @@ -13749,6 +13766,8 @@ sub print_reports { my @groupby = @{$args{groupby}}; my @orderby = @{$args{orderby}}; + my $show_all = $o->get('show-all'); + for my $i ( 0..$#groupby ) { if ( $o->get('report') || $qv || $qh ) { $eas->[$i]->calculate_statistical_metrics(); @@ -13799,6 +13818,7 @@ sub print_reports { OptionParser => $args{OptionParser}, QueryParser => $args{QueryParser}, Quoter => $args{Quoter}, + show_all => $show_all, ); $qrf->print_reports( @@ -15502,6 +15522,18 @@ example, specifying C<--set-vars wait_timeout=500> overrides the defaultvalue of The tool prints a warning and continues if a variable cannot be set. +=item --show-all + +type: Hash + +Show all values for these attributes. + +By default pt-query-digest only shows as many of an attribute's value that +fit on a single line. This option allows you to specify attributes for which +all values will be shown (line width is ignored). This only works for +attributes with string values like user, host, db, etc. Multiple attributes +can be specified, comma-separated. + =item --since type: string diff --git a/lib/QueryReportFormatter.pm b/lib/QueryReportFormatter.pm index 14fbce32..3b332830 100644 --- a/lib/QueryReportFormatter.pm +++ b/lib/QueryReportFormatter.pm @@ -84,6 +84,12 @@ has event_headers => ( default => sub { [qw(pct total min max avg 95% stddev median)] }, ); +has show_all => ( + is => 'ro', + isa => 'HashRef', + default => sub { {} }, +); + has ReportFormatter => ( is => 'ro', isa => 'ReportFormatter', @@ -1114,13 +1120,15 @@ sub bool_percents { # Does pretty-printing for lists of strings like users, hosts, db. sub format_string_list { my ( $self, $attrib, $vals, $class_cnt ) = @_; - + # Only class result values have unq. So if unq doesn't exist, # then we've been given global values. if ( !exists $vals->{unq} ) { return ($vals->{cnt}); } + my $show_all = $self->show_all(); + my $cnt_for = $vals->{unq}; if ( 1 == keys %$cnt_for ) { my ($str) = keys %$cnt_for; @@ -1146,6 +1154,9 @@ sub format_string_list { } my $p = percentage_of($cnt_for->{$str}, $class_cnt); $print_str .= " ($cnt_for->{$str}/$p%)"; + if ( !$show_all->{$attrib} ) { + last if (length $line) + (length $print_str) > LINE_LENGTH - 27; + } $line .= "$print_str, "; $i++; } diff --git a/t/lib/samples/QueryReportFormatter/report012.txt b/t/lib/samples/QueryReportFormatter/report012.txt index 6e648d59..330f8d68 100644 --- a/t/lib/samples/QueryReportFormatter/report012.txt +++ b/t/lib/samples/QueryReportFormatter/report012.txt @@ -7,4 +7,4 @@ # Count 100 3 # Exec time 100 6s 1s 3s 2s 3s 780ms 2s # String: -# foo Hi. I'm a... (1/33%), Me too! I'... (1/33%), Number 3 l... (1/33%) +# foo Hi. I'm a... (1/33%), Me too! I'... (1/33%)... 1 more diff --git a/t/lib/samples/QueryReportFormatter/report013.txt b/t/lib/samples/QueryReportFormatter/report013.txt index e6c3c34c..3ff99d58 100644 --- a/t/lib/samples/QueryReportFormatter/report013.txt +++ b/t/lib/samples/QueryReportFormatter/report013.txt @@ -5,4 +5,4 @@ # Count 100 2 # Exec time 100 16s 8s 8s 8s 8s 0 8s # String: -# Hosts 123.123.123.456 (1/50%), 123.123.123.789 (1/50%) +# Hosts 123.123.123.456 (1/50%)... 1 more diff --git a/t/lib/samples/QueryReportFormatter/report014.txt b/t/lib/samples/QueryReportFormatter/report014.txt index 382a228c..782b0010 100644 --- a/t/lib/samples/QueryReportFormatter/report014.txt +++ b/t/lib/samples/QueryReportFormatter/report014.txt @@ -5,4 +5,4 @@ # Count 100 3 # Exec time 100 24s 8s 8s 8s 8s 0 8s # String: -# Hosts 123.123.123.456 (1/33%), 123.123.123.789 (1/33%), 123.123.123.999 (1/33%) +# Hosts 123.123.123.456 (1/33%)... 2 more diff --git a/t/lib/samples/QueryReportFormatter/report015.txt b/t/lib/samples/QueryReportFormatter/report015.txt index 382a228c..782b0010 100644 --- a/t/lib/samples/QueryReportFormatter/report015.txt +++ b/t/lib/samples/QueryReportFormatter/report015.txt @@ -5,4 +5,4 @@ # Count 100 3 # Exec time 100 24s 8s 8s 8s 8s 0 8s # String: -# Hosts 123.123.123.456 (1/33%), 123.123.123.789 (1/33%), 123.123.123.999 (1/33%) +# Hosts 123.123.123.456 (1/33%)... 2 more diff --git a/t/pt-query-digest/samples/slow042-show-all-host.txt b/t/pt-query-digest/samples/slow042-show-all-host.txt index fe9f56dc..bee41e47 100644 --- a/t/pt-query-digest/samples/slow042-show-all-host.txt +++ b/t/pt-query-digest/samples/slow042-show-all-host.txt @@ -14,7 +14,7 @@ # Rows read 100 690 230 230 230 230 0 230 # Query size 100 31 10 11 10.33 10.84 0.47 9.83 # String: -# Hosts 123.123.123.121 (1/33%), 123.123.123.122 (1/33%), 123.123.123.123 (1/33%) +# Hosts 123.123.123.121 (1/33%)... 2 more # Users chessguest # Query_time distribution # 1us diff --git a/t/pt-query-digest/samples/slow053.txt b/t/pt-query-digest/samples/slow053.txt index 721e121e..51fec151 100644 --- a/t/pt-query-digest/samples/slow053.txt +++ b/t/pt-query-digest/samples/slow053.txt @@ -72,7 +72,7 @@ SELECT * FROM bar WHERE id=12\G # Rows examine 0 0 0 0 0 0 0 0 # Query size 45 140 28 28 28 28 0 28 # String: -# arg crc 108 (1/20%), 306 (1/20%), 353 (1/20%), 558 (1/20%), 887 (1/20%) +# arg crc 108 (1/20%), 306 (1/20%), 353 (1/20%)... 2 more # Query_time distribution # 1us # 10us ################################################################ diff --git a/t/pt-query-digest/samples/slow054.txt b/t/pt-query-digest/samples/slow054.txt index 63d6f20e..ed380133 100644 --- a/t/pt-query-digest/samples/slow054.txt +++ b/t/pt-query-digest/samples/slow054.txt @@ -12,7 +12,7 @@ # Rows examine 0 0 0 0 0 0 0 0 # Query size 100 224 28 28 28 28 0 28 # String: -# 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%) +# InnoDB trxID 101 (1/12%), 102 (1/12%), 103 (1/12%)... 5 more # Query_time distribution # 1us # 10us ################################################################ diff --git a/t/pt-query-digest/samples/tcpdump033.txt b/t/pt-query-digest/samples/tcpdump033.txt index a9c85ff2..e392dfb1 100644 --- a/t/pt-query-digest/samples/tcpdump033.txt +++ b/t/pt-query-digest/samples/tcpdump033.txt @@ -56,7 +56,7 @@ select * from d.t where name="adam"\G # Warning coun 0 0 0 0 0 0 0 0 # String: # Hosts 127.0.0.1 -# Statement id 2 (1/20%), 3 (1/20%), 4 (1/20%), 5 (1/20%), 6 (1/20%) +# Statement id 2 (1/20%), 3 (1/20%), 4 (1/20%), 5 (1/20%)... 1 more # Query_time distribution # 1us # 10us