line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Sphinx::Log::Parser; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
BEGIN { |
4
|
2
|
|
|
2
|
|
127630
|
$Sphinx::Log::Parser::VERSION = '0.03'; |
5
|
|
|
|
|
|
|
} |
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
21
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
78
|
|
8
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
65
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# ABSTRACT: parse Sphinx searchd log |
11
|
|
|
|
|
|
|
|
12
|
2
|
|
|
2
|
|
16
|
use Carp; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
316
|
|
13
|
2
|
|
|
2
|
|
3456
|
use IO::File; |
|
2
|
|
|
|
|
28108
|
|
|
2
|
|
|
|
|
286
|
|
14
|
2
|
|
|
2
|
|
19
|
use IO::Handle; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
1705
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub new { |
17
|
1
|
|
|
1
|
0
|
16
|
my ( $class, $file ) = @_; |
18
|
|
|
|
|
|
|
|
19
|
1
|
|
|
|
|
2
|
my %data; |
20
|
1
|
50
|
|
|
|
19
|
if ( UNIVERSAL::isa( $file, 'IO::Handle' ) ) { |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
21
|
0
|
|
|
|
|
0
|
$data{file} = $file; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
elsif ( UNIVERSAL::isa( $file, 'File::Tail' ) ) { |
24
|
0
|
|
|
|
|
0
|
$data{file} = $file; |
25
|
0
|
|
|
|
|
0
|
$data{filetail} = 1; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
elsif ( !ref $file ) { |
28
|
1
|
50
|
|
|
|
3
|
if ( $file eq '-' ) { |
29
|
0
|
|
|
|
|
0
|
my $io = new IO::Handle; |
30
|
0
|
|
|
|
|
0
|
$data{file} = $io->fdopen( fileno(STDIN), "r" ); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
else { |
33
|
1
|
|
|
|
|
9
|
$data{file} = new IO::File( $file, "<" ); |
34
|
1
|
50
|
|
|
|
168
|
defined $data{file} or croak "can't open $file: $!"; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
else { |
38
|
0
|
|
|
|
|
0
|
croak |
39
|
|
|
|
|
|
|
"argument must be either a file-name or an IO::Handle/File::Tail object."; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
1
|
|
|
|
|
5
|
return bless \%data, $class; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub _next_line { |
46
|
4
|
|
|
4
|
|
6
|
my $self = shift; |
47
|
4
|
|
|
|
|
9
|
my $f = $self->{file}; |
48
|
4
|
50
|
|
|
|
10
|
if ( defined $self->{filetail} ) { |
49
|
0
|
|
|
|
|
0
|
return $f->read; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
else { |
52
|
4
|
|
|
|
|
120
|
return $f->getline; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub next { |
57
|
4
|
|
|
4
|
0
|
22
|
my ($self) = @_; |
58
|
|
|
|
|
|
|
|
59
|
4
|
|
|
|
|
10
|
while ( defined( my $str = $self->_next_line ) ) { |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# 0.9.9 |
62
|
|
|
|
|
|
|
# [query-date] query-time multiquery-factor [match-mode/filters-count/sort-mode total-matches (offset,limit) @groupby-attr] [index-name] [performances-counters] [query-comment] query |
63
|
|
|
|
|
|
|
# optionals: multiquery-factor, @groupby-attr, performances-counters, query-comment |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# '[Mon Sep 20 06:25:29.979 2010] ' |
66
|
|
|
|
|
|
|
# '0.005 sec x20 ' |
67
|
|
|
|
|
|
|
# '[ext/3/ext 163 (0,100) @perf_id] ' |
68
|
|
|
|
|
|
|
# '[index1 index2] ' |
69
|
|
|
|
|
|
|
# '[ios=5 kb=45.6 ioms=65.57 cpums=2.5] ' |
70
|
|
|
|
|
|
|
# '[query comment] ' |
71
|
|
|
|
|
|
|
# '@author (Days Gracie) ' |
72
|
|
|
|
|
|
|
|
73
|
3
|
|
|
|
|
146
|
$str =~ /^ |
74
|
|
|
|
|
|
|
\[(\w{3}\s+\w{3}\s+\d{1,2}\s+\d{2}:\d{2}:\d{2}\.\d{3}\s+\d{4})\]\s+ |
75
|
|
|
|
|
|
|
([\d\.]+)\s+sec\s+(x[\d]+)?\s? |
76
|
|
|
|
|
|
|
\[(\w+)\/(\d+)\/([\w\-\+]+)\s(\d+)\s\((\d+)\,(\d+)\)\s*\@?(\S+)?\]\s+ |
77
|
|
|
|
|
|
|
\[([\w\s\;]+)\]\s+ |
78
|
|
|
|
|
|
|
(\[ios\=[\d\.]+\s+kb\=[\d\.]+\s+ioms\=[\d\.]+[\s+cpums\=[\d\.]+]?\])?\s? |
79
|
|
|
|
|
|
|
(\[.*\])?\s? |
80
|
|
|
|
|
|
|
(.*) |
81
|
|
|
|
|
|
|
$/x; |
82
|
|
|
|
|
|
|
|
83
|
3
|
|
|
|
|
9
|
my $query_date = $1; |
84
|
3
|
|
|
|
|
7
|
my $query_time = $2; |
85
|
3
|
|
|
|
|
6
|
my $multiquery_factor = $3; |
86
|
3
|
|
|
|
|
7
|
my $match_mode = $4; |
87
|
3
|
|
|
|
|
5
|
my $filter_count = $5; |
88
|
3
|
|
|
|
|
6
|
my $sort_mode = $6; |
89
|
3
|
|
|
|
|
4
|
my $total_matches = $7; |
90
|
3
|
|
|
|
|
6
|
my $offset = $8; |
91
|
3
|
|
|
|
|
6
|
my $limit = $9; |
92
|
3
|
|
|
|
|
4
|
my $groupby_attr = $10; |
93
|
3
|
|
|
|
|
5
|
my $index_name = $11; |
94
|
3
|
|
|
|
|
5
|
my $performances_counters = $12; |
95
|
3
|
|
|
|
|
5
|
my $query_comment = $13; |
96
|
3
|
|
|
|
|
5
|
my $query = $14; |
97
|
|
|
|
|
|
|
|
98
|
3
|
100
|
|
|
|
14
|
$performances_counters =~ s/\[(.*)\]/$1/ if $performances_counters; |
99
|
3
|
50
|
|
|
|
8
|
$query_comment =~ s/\[(.*)\]/$1/ if $query_comment; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
return { |
102
|
3
|
|
|
|
|
36
|
query_date => $query_date, |
103
|
|
|
|
|
|
|
multiquery_factor => $multiquery_factor, |
104
|
|
|
|
|
|
|
query_time => $query_time, |
105
|
|
|
|
|
|
|
match_mode => $match_mode, |
106
|
|
|
|
|
|
|
filter_count => $filter_count, |
107
|
|
|
|
|
|
|
sort_mode => $sort_mode, |
108
|
|
|
|
|
|
|
total_matches => $total_matches, |
109
|
|
|
|
|
|
|
offset => $offset, |
110
|
|
|
|
|
|
|
limit => $limit, |
111
|
|
|
|
|
|
|
groupby_attr => $groupby_attr, |
112
|
|
|
|
|
|
|
index_name => $index_name, |
113
|
|
|
|
|
|
|
performances_counters => $performances_counters, |
114
|
|
|
|
|
|
|
query_comment => $query_comment, |
115
|
|
|
|
|
|
|
query => $query |
116
|
|
|
|
|
|
|
}; |
117
|
|
|
|
|
|
|
} |
118
|
1
|
|
|
|
|
32
|
return; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
1; |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
__END__ |