line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test2::Plugin::DBIProfile; |
2
|
1
|
|
|
1
|
|
62082
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
23
|
|
3
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
33
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.002004'; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
564
|
use DBI::Profile qw/dbi_profile_merge_nodes/; |
|
1
|
|
|
|
|
18638
|
|
|
1
|
|
|
|
|
56
|
|
8
|
1
|
|
|
1
|
|
6
|
use Test2::API qw/test2_add_callback_exit/; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
49
|
|
9
|
1
|
|
|
1
|
|
454
|
use Test2::Util::Times qw/render_duration/; |
|
1
|
|
|
|
|
530
|
|
|
1
|
|
|
|
|
265
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
my $ADDED_HOOK = 0; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub import { |
14
|
1
|
|
|
1
|
|
26
|
my $class = shift; |
15
|
1
|
|
|
|
|
2
|
my ($path) = @_; |
16
|
|
|
|
|
|
|
|
17
|
1
|
50
|
|
|
|
3
|
if (defined $path) { |
18
|
0
|
|
|
|
|
0
|
$ENV{DBI_PROFILE} = $path; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
else { |
21
|
1
|
|
50
|
|
|
10
|
$ENV{DBI_PROFILE} //= "!MethodClass"; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
1
|
50
|
|
|
|
4
|
return if $ADDED_HOOK++; |
25
|
|
|
|
|
|
|
|
26
|
1
|
|
|
|
|
3
|
$DBI::Profile::ON_DESTROY_DUMP = undef; |
27
|
1
|
|
|
|
|
4
|
$DBI::Profile::ON_FLUSH_DUMP = undef; |
28
|
|
|
|
|
|
|
|
29
|
1
|
|
|
|
|
1
|
my $ran = 0; |
30
|
|
|
|
|
|
|
my $callback = sub { |
31
|
2
|
100
|
|
2
|
|
16629
|
return if $ran++; |
32
|
1
|
|
|
|
|
4
|
send_profile_event(@_); |
33
|
1
|
|
|
|
|
4
|
}; |
34
|
|
|
|
|
|
|
|
35
|
1
|
|
|
|
|
11
|
test2_add_callback_exit($callback); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# Fallback |
38
|
1
|
50
|
|
1
|
|
36407
|
eval 'END { local $?; $callback->() }; 1' or die $@; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
61
|
|
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub send_profile_event { |
42
|
1
|
|
|
1
|
0
|
3
|
my ($ctx, $real, $new) = @_; |
43
|
|
|
|
|
|
|
|
44
|
1
|
50
|
|
|
|
3
|
my $p = $DBI::shared_profile or return; |
45
|
|
|
|
|
|
|
|
46
|
1
|
|
|
|
|
3
|
my $data = $p->{Data}; |
47
|
1
|
|
|
|
|
4
|
my ($summary) = $p->format; |
48
|
|
|
|
|
|
|
|
49
|
1
|
|
|
|
|
326
|
my @totals; |
50
|
1
|
|
|
|
|
8
|
dbi_profile_merge_nodes(\@totals, $data); |
51
|
1
|
|
|
|
|
2
|
my ($count, $time) = @totals; |
52
|
|
|
|
|
|
|
|
53
|
1
|
|
|
|
|
9
|
$ctx->send_ev2( |
54
|
|
|
|
|
|
|
dbi_profile => $data, |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
about => {package => __PACKAGE__, details => $summary}, |
57
|
|
|
|
|
|
|
info => [{tag => 'DBI-PROF', details => $summary}], |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
harness_job_fields => [ |
60
|
|
|
|
|
|
|
{name => "dbi_time", details => render_duration($time), raw => $time}, |
61
|
|
|
|
|
|
|
{name => "dbi_calls", details => $count}, |
62
|
|
|
|
|
|
|
], |
63
|
|
|
|
|
|
|
); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
1; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
__END__ |