line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Devel::KYTProf::Profiler::DBI; |
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
3525
|
use strict; |
|
6
|
|
|
|
|
15
|
|
|
6
|
|
|
|
|
189
|
|
4
|
6
|
|
|
6
|
|
31
|
use warnings; |
|
6
|
|
|
|
|
20
|
|
|
6
|
|
|
|
|
179
|
|
5
|
6
|
|
|
6
|
|
2660
|
use DBIx::Tracer; |
|
6
|
|
|
|
|
11386
|
|
|
6
|
|
|
|
|
2072
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub apply { |
8
|
|
|
|
|
|
|
Devel::KYTProf->add_prof( |
9
|
|
|
|
|
|
|
'DBI', |
10
|
|
|
|
|
|
|
'connect', |
11
|
|
|
|
|
|
|
sub { |
12
|
1
|
|
|
1
|
|
4
|
my ($orig, $class, $dsn, $user, $pass, $attr) = @_; |
13
|
|
|
|
|
|
|
return [ |
14
|
|
|
|
|
|
|
'%s %s', |
15
|
|
|
|
|
|
|
['dbi_connect_method', 'dsn'], |
16
|
|
|
|
|
|
|
{ |
17
|
1
|
|
50
|
|
|
25
|
dbi_connect_method => $attr->{dbi_connect_method} || 'connect', |
18
|
|
|
|
|
|
|
dsn => $dsn, |
19
|
|
|
|
|
|
|
}, |
20
|
|
|
|
|
|
|
]; |
21
|
|
|
|
|
|
|
} |
22
|
6
|
|
|
6
|
0
|
59
|
); |
23
|
|
|
|
|
|
|
|
24
|
6
|
|
|
|
|
19
|
my $LastSQL; |
25
|
|
|
|
|
|
|
my $LastBinds; |
26
|
6
|
|
|
|
|
0
|
my $IsInProf; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
our $_TRACER = DBIx::Tracer->new(sub { |
29
|
3
|
|
|
3
|
|
719
|
my %args = @_; |
30
|
3
|
|
|
|
|
7
|
$LastSQL = $args{sql}; |
31
|
3
|
|
50
|
|
|
22
|
my $bind_params = $args{bind_params} || []; |
32
|
|
|
|
|
|
|
$LastBinds = scalar(@$bind_params) ? |
33
|
3
|
50
|
|
|
|
15
|
'(bind: '.join(', ', map { defined $_ ? $_ : 'undef' } @$bind_params).')' : |
|
4
|
100
|
|
|
|
25
|
|
34
|
|
|
|
|
|
|
''; |
35
|
6
|
|
|
|
|
32
|
}); |
36
|
|
|
|
|
|
|
Devel::KYTProf->add_prof( |
37
|
|
|
|
|
|
|
'DBI::st', |
38
|
|
|
|
|
|
|
'execute', |
39
|
|
|
|
|
|
|
sub { |
40
|
2
|
|
|
2
|
|
5
|
my (undef, $sth) = @_; |
41
|
|
|
|
|
|
|
return [ |
42
|
2
|
|
|
|
|
30
|
'%s %s (%d rows)', |
43
|
|
|
|
|
|
|
['sql', 'sql_binds', 'rows'], |
44
|
|
|
|
|
|
|
{ |
45
|
|
|
|
|
|
|
sql => $LastSQL, |
46
|
|
|
|
|
|
|
sql_binds => $LastBinds, |
47
|
|
|
|
|
|
|
rows => $sth->rows, |
48
|
|
|
|
|
|
|
}, |
49
|
|
|
|
|
|
|
]; |
50
|
|
|
|
|
|
|
}, |
51
|
2
|
|
|
2
|
|
7
|
sub { !$IsInProf }, |
52
|
6
|
|
|
|
|
419
|
); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
Devel::KYTProf->add_profs( |
55
|
|
|
|
|
|
|
'DBI::db', |
56
|
|
|
|
|
|
|
[qw/do selectall_arrayref selectrow_arrayref selectrow_array/], |
57
|
|
|
|
|
|
|
sub { |
58
|
1
|
|
|
1
|
|
3
|
undef $IsInProf; |
59
|
|
|
|
|
|
|
return [ |
60
|
1
|
|
|
|
|
7
|
'%s %s', |
61
|
|
|
|
|
|
|
['sql', 'sql_binds'], |
62
|
|
|
|
|
|
|
{ |
63
|
|
|
|
|
|
|
sql => $LastSQL, |
64
|
|
|
|
|
|
|
sql_binds => $LastBinds, |
65
|
|
|
|
|
|
|
}, |
66
|
|
|
|
|
|
|
]; |
67
|
|
|
|
|
|
|
}, |
68
|
|
|
|
|
|
|
# Since there is a possibility that these methods call `execute` method |
69
|
|
|
|
|
|
|
# internally (it depends on DBD implementation), we flag here to prevent |
70
|
|
|
|
|
|
|
# duplicate profiling output. |
71
|
|
|
|
|
|
|
# And we drop this flag in the above callback. |
72
|
1
|
|
|
1
|
|
3
|
sub { $IsInProf = 1 }, |
73
|
6
|
|
|
|
|
47
|
); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
1; |