diff --git a/bin/pt-query-digest b/bin/pt-query-digest index 3b693bcf..a4b29c26 100755 --- a/bin/pt-query-digest +++ b/bin/pt-query-digest @@ -6525,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', @@ -7404,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; @@ -7433,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++; } @@ -13764,6 +13775,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(); @@ -13814,6 +13827,7 @@ sub print_reports { OptionParser => $args{OptionParser}, QueryParser => $args{QueryParser}, Quoter => $args{Quoter}, + show_all => $show_all, ); $qrf->print_reports( @@ -15517,6 +15531,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