pqd: Restore the --show-all option

This commit is contained in:
Brian Fraser
2013-04-08 09:53:52 -03:00
parent f8999689b5
commit 1dcc6904f3
10 changed files with 63 additions and 20 deletions

View File

@@ -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

View File

@@ -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++;
}

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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 ################################################################

View File

@@ -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 ################################################################

View File

@@ -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