line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DBIx::LogProfile; |
2
|
1
|
|
|
1
|
|
68440
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
3
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
4
|
1
|
|
|
1
|
|
456
|
use parent 'DBI::Profile'; |
|
1
|
|
|
|
|
299
|
|
|
1
|
|
|
|
|
6
|
|
5
|
1
|
|
|
1
|
|
23875
|
use Log::Any; |
|
1
|
|
|
|
|
10491
|
|
|
1
|
|
|
|
|
4
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = 0.01; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub new { |
10
|
|
|
|
|
|
|
|
11
|
0
|
|
|
0
|
1
|
|
my $pkg = shift; |
12
|
|
|
|
|
|
|
|
13
|
0
|
|
|
|
|
|
my $self = $pkg->SUPER::new( |
14
|
|
|
|
|
|
|
Log => 'Any', |
15
|
|
|
|
|
|
|
OrderByDesc => 'longest_duration', |
16
|
|
|
|
|
|
|
Limit => undef, |
17
|
|
|
|
|
|
|
Level => 'trace', |
18
|
|
|
|
|
|
|
@_, |
19
|
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# sanity check the method name. if something like debugf is |
22
|
|
|
|
|
|
|
# specified, strange things may happen, but not dangerous. |
23
|
0
|
0
|
|
|
|
|
die unless $self->{Level} =~ /^[a-z]+$/; |
24
|
|
|
|
|
|
|
|
25
|
0
|
0
|
|
|
|
|
if ($self->{Log} eq 'Any') { |
|
|
0
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
} elsif ($self->{Log} eq 'Log4perl') { |
28
|
0
|
|
|
|
|
|
eval "require Log::Log4perl"; |
29
|
0
|
|
|
|
|
|
eval "require Log::Log4perl::MDC"; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
} else { |
32
|
0
|
|
|
|
|
|
die "Bad Log parameter `$self->{Log}`. Must be Any or Log4perl." |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
DBI->trace_msg("$self: @{[ %$self ]}\n", 0) |
37
|
0
|
0
|
0
|
|
|
|
if $self->{Trace} && $self->{Trace} >= 2; |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
return $self; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub flush_to_logger { |
43
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
44
|
0
|
|
|
|
|
|
my $class = ref $self; |
45
|
0
|
|
|
|
|
|
my $data = $self->{Data}; |
46
|
0
|
|
|
|
|
|
my $method = $self->{Level}; |
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
my @fields = qw/ |
49
|
|
|
|
|
|
|
count |
50
|
|
|
|
|
|
|
total_duration |
51
|
|
|
|
|
|
|
first_duration |
52
|
|
|
|
|
|
|
shortest_duration |
53
|
|
|
|
|
|
|
longest_duration |
54
|
|
|
|
|
|
|
time_of_first_sample |
55
|
|
|
|
|
|
|
time_of_last_sample |
56
|
|
|
|
|
|
|
/; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
my @nodes = map { |
59
|
0
|
|
|
|
|
|
my ($statistics, @keys) = @$_; |
|
0
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
my %h; |
62
|
0
|
|
|
|
|
|
@h{ @fields } = @$statistics; |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
$h{path} = join ':', @{ $self->{Path} }; |
|
0
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
for my $i ( 1 .. @keys ) { |
67
|
0
|
|
|
|
|
|
$h{ "key$i" } = $keys[ $i - 1 ]; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
\%h; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
} $self->as_node_path_list(); |
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
my @sorted; |
75
|
|
|
|
|
|
|
|
76
|
0
|
0
|
|
|
|
|
if ($self->{OrderByDesc} !~ /^key/) { |
77
|
|
|
|
|
|
|
@sorted = sort { |
78
|
0
|
|
|
|
|
|
$b->{ $self->{OrderByDesc} } |
79
|
|
|
|
|
|
|
<=> |
80
|
|
|
|
|
|
|
$a->{ $self->{OrderByDesc} } |
81
|
0
|
|
|
|
|
|
} @nodes; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
} else { |
84
|
|
|
|
|
|
|
@sorted = sort { |
85
|
0
|
|
|
|
|
|
$b->{ $self->{OrderByDesc} } |
86
|
|
|
|
|
|
|
cmp |
87
|
|
|
|
|
|
|
$a->{ $self->{OrderByDesc} } |
88
|
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
} @nodes; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
|
my $counter = 0; |
94
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
eval { |
96
|
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
|
for my $h (@sorted) { |
98
|
|
|
|
|
|
|
|
99
|
0
|
0
|
|
|
|
|
if ($self->{Log} eq 'Log4perl') { |
|
|
0
|
|
|
|
|
|
100
|
0
|
|
|
|
|
|
my $ctx = Log::Log4perl::MDC->get_context(); |
101
|
|
|
|
|
|
|
|
102
|
0
|
|
|
|
|
|
local @{ $ctx }{ keys %$h } = values %$h; |
|
0
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
|
104
|
0
|
|
|
|
|
|
Log::Log4perl->get_logger()->$method(__PACKAGE__); |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
} elsif ($self->{Log} eq 'Any') { |
107
|
0
|
|
|
|
|
|
Log::Any->get_logger()->$method(__PACKAGE__, $h); |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
0
|
0
|
|
|
|
|
if (defined $self->{Limit}) { |
112
|
0
|
0
|
|
|
|
|
last if ++$counter >= $self->{Limit}; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
}; |
117
|
|
|
|
|
|
|
|
118
|
0
|
0
|
|
|
|
|
if ($@) { |
119
|
|
|
|
|
|
|
|
120
|
0
|
|
|
|
|
|
Log::Any->get_logger()->errorf( |
121
|
|
|
|
|
|
|
"%s caught exception: %s", |
122
|
|
|
|
|
|
|
__PACKAGE__, |
123
|
|
|
|
|
|
|
$@ |
124
|
|
|
|
|
|
|
); |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
0
|
|
|
|
|
|
$self->empty(); |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub on_destroy { |
133
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
134
|
0
|
0
|
|
|
|
|
return if ${^GLOBAL_PHASE} eq 'DESTRUCT'; |
135
|
0
|
|
|
|
|
|
$self->flush_to_logger(); |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
sub DESTROY { |
139
|
0
|
|
|
0
|
|
|
on_destroy(@_); |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
END { |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
DBI->visit_handles(sub { |
145
|
0
|
|
|
|
|
|
my ($dbh, $info) = @_; |
146
|
0
|
0
|
|
|
|
|
return unless UNIVERSAL::isa($dbh->{Profile}, __PACKAGE__); |
147
|
0
|
|
|
|
|
|
$dbh->{Profile}->flush_to_logger(); |
148
|
1
|
|
|
1
|
|
232
|
}); |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
}; |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
1; |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
__END__ |