mirror of
https://github.com/percona/percona-toolkit.git
synced 2026-05-02 01:01:09 +08:00
Add RawLogParser.pm and implement --type rawlog in pt-query-digest (Percona 22371).
This commit is contained in:
+82
-1
@@ -9674,6 +9674,86 @@ sub _d {
|
||||
# End GeneralLogParser package
|
||||
# ###########################################################################
|
||||
|
||||
# ###########################################################################
|
||||
# RawLogParser package
|
||||
# This package is a copy without comments from the original. The original
|
||||
# with comments and its test file can be found in the Bazaar repository at,
|
||||
# lib/RawLogParser.pm
|
||||
# t/lib/RawLogParser.t
|
||||
# See https://launchpad.net/percona-toolkit for more information.
|
||||
# ###########################################################################
|
||||
{
|
||||
package RawLogParser;
|
||||
|
||||
use strict;
|
||||
use warnings FATAL => 'all';
|
||||
use English qw(-no_match_vars);
|
||||
use constant PTDEBUG => $ENV{PTDEBUG} || 0;
|
||||
|
||||
use Data::Dumper;
|
||||
$Data::Dumper::Indent = 1;
|
||||
$Data::Dumper::Sortkeys = 1;
|
||||
$Data::Dumper::Quotekeys = 0;
|
||||
|
||||
sub new {
|
||||
my ( $class ) = @_;
|
||||
my $self = {
|
||||
};
|
||||
return bless $self, $class;
|
||||
}
|
||||
|
||||
sub parse_event {
|
||||
my ( $self, %args ) = @_;
|
||||
my @required_args = qw(next_event tell);
|
||||
foreach my $arg ( @required_args ) {
|
||||
die "I need a $arg argument" unless $args{$arg};
|
||||
}
|
||||
my ($next_event, $tell) = @args{@required_args};
|
||||
|
||||
my $line;
|
||||
my $pos_in_log = $tell->();
|
||||
LINE:
|
||||
while ( defined($line = $next_event->()) ) {
|
||||
PTDEBUG && _d($line);
|
||||
chomp($line);
|
||||
my @properties = (
|
||||
'pos_in_log', $pos_in_log,
|
||||
'cmd', 'Query',
|
||||
'bytes', length($line),
|
||||
'Query_time', 0,
|
||||
'arg', $line,
|
||||
);
|
||||
|
||||
$pos_in_log = $tell->();
|
||||
|
||||
PTDEBUG && _d('Properties of event:', Dumper(\@properties));
|
||||
my $event = { @properties };
|
||||
if ( $args{stats} ) {
|
||||
$args{stats}->{events_read}++;
|
||||
$args{stats}->{events_parsed}++;
|
||||
}
|
||||
|
||||
return $event;
|
||||
}
|
||||
|
||||
$args{oktorun}->(0) if $args{oktorun};
|
||||
return;
|
||||
}
|
||||
|
||||
sub _d {
|
||||
my ($package, undef, $line) = caller 0;
|
||||
@_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
|
||||
map { defined $_ ? $_ : 'undef' }
|
||||
@_;
|
||||
print STDERR "# $package:$line $PID ", join(' ', @_), "\n";
|
||||
}
|
||||
|
||||
1;
|
||||
}
|
||||
# ###########################################################################
|
||||
# End RawLogParser package
|
||||
# ###########################################################################
|
||||
|
||||
# ###########################################################################
|
||||
# ProtocolParser package
|
||||
# This package is a copy without comments from the original. The original
|
||||
@@ -11838,7 +11918,7 @@ sub main {
|
||||
my $review_dsn = $o->get('review');
|
||||
my @groupby = @{$o->get('group-by')};
|
||||
my @orderby;
|
||||
if ( (grep { $_ eq 'genlog' || $_ eq 'GeneralLogParser' } @{$o->get('type')})
|
||||
if ( (grep { $_ =~ m/genlog|GeneralLogParser|rawlog|RawLogParser/ } @{$o->get('type')})
|
||||
&& !$o->got('order-by') ) {
|
||||
@orderby = 'Query_time:cnt';
|
||||
}
|
||||
@@ -12274,6 +12354,7 @@ sub main {
|
||||
'MemcachedEvent'],
|
||||
http => ['TcpdumpParser','HTTPProtocolParser'],
|
||||
pglog => ['PgLogParser'],
|
||||
rawlog => ['RawLogParser'],
|
||||
);
|
||||
my $type = $o->get('type');
|
||||
$type = $alias_for{$type->[0]} if $alias_for{$type->[0]};
|
||||
|
||||
Reference in New Issue
Block a user