blib/lib/Plack/Middleware/Debug/DBIProfile.pm

filter: Statementstmt 43.1% 22 / 51 Branchbran 0.0% 0 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 53.3% 8 / 15 Podpod 100% 2 / 2 totaltotal 40.0% 32 / 80 CC 7 SCAR 19.3
CC
7
Cov
35%
__ANON__
20.0
prepare_app
12.0
_set_profile_on_all_dbi_handles
6.0
CRAP 6.9
↑ Summary
1 package Plack::Middleware::Debug::DBIProfile;
2 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 $Plack::Middleware::Debug::DBIProfile::VERSION = '0.102';
4 }
5  
6 1 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use Plack::Util::Accessor qw(profile format);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use parent qw(Plack::Middleware::Debug::Base);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 ▶use DBI::Profile;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Time::HiRes qw(gettimeofday);
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16  
17 0 ▶sub prepare_app {
Subroutine prepare_app: not called CC=3 SCAR=24.8
Pod documented
18 0 my $self = shift;
19  
20 0 ▶ $self->profile(1)
Branch: 1 branch
BranchTrueFalseTotal
unless $self->profile 0 0 0
21 unless $self->profile;
22  
23 0 ▶ $self->format("Profile Path: %1\$s\nProfile Data: %11\$fs / %10\$d = %2\$fs avg (first %12\$fs, min %13\$fs, max %14\$fs)\n")
Branch: 1 branch
BranchTrueFalseTotal
unless $self->format 0 0 0
24 unless $self->format;
25 }
26  
27  
28 0 ▶sub run {
Subroutine run: not called CC=1 SCAR=6.9
Pod documented
29 0 my($self, $env, $panel) = @_;
30  
31 0 $panel->nav_title("DBI Profile");
32  
33 0 my $profile_obj = _set_profile_on_all_dbi_handles($self->profile);
34 0 my $start_time = gettimeofday();
35  
36 0 ▶ return sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
37 0 my $res = shift;
38  
39 0 ▶ if ($profile_obj) {
Branch: 1 branch
BranchTrueFalseTotal
if ($profile_obj) 0 0 0
40 0 my $duration = gettimeofday() - $start_time;
41 0 my $time_in_dbi = dbi_profile_merge_nodes(my $totals=[], $profile_obj->{Data});
42  
43 0 my $sep = "_" x 75;
44 my @items = $profile_obj->as_text({
45 format => $self->format."\n$sep\n",
46 0 ▶ sortsub => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
47 0 my $ary = shift;
48 0 @$ary = sort { $b->[0][1] <=> $a->[0][1] } @$ary;
49 },
50 0 });
51 0 $panel->content($self->render_lines(join "", @items));
52  
53 0 ▶ my $subtitle = sprintf "%.3f s (%d%%)",
Branch: 1 branch
BranchTrueFalseTotal
$duration ? : 0 0 0
54 $time_in_dbi, ($duration) ? $time_in_dbi/$duration*100 : "-";
55 # only show item count if >1 because they'll always be one
56 # for profile==1, the default, so it's only noise, and for other
57 # profile levels they'll always be an extra 'empty' item for
58 # calls that can't be associated with a particular statement etc.
59 0 ▶ $subtitle .= " #".@items if @items > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @items > 1 0 0 0
60 0 $panel->nav_subtitle($subtitle);
61  
62 # disable profiling and silently discard profile data
63 0 ▶ local $DBI::Profile::ON_DESTROY_DUMP = sub { };
Subroutine __ANON__: not called CC=1 SCAR=6.9
64 0 _set_profile_on_all_dbi_handles(undef);
65 }
66 0 };
67 }
68  
69  
70 0 ▶sub _set_profile_on_all_dbi_handles {
Subroutine _set_profile_on_all_dbi_handles: not called CC=2 SCAR=17.9
71 0 my ($profile_spec) = @_;
72  
73 # for drivers we've not loaded yet
74 0 ▶ $DBI::shared_profile = ($profile_spec)
Branch: 1 branch
BranchTrueFalseTotal
$profile_spec ? : 0 0 0
75 ? DBI::Profile->_auto_new($profile_spec) # XXX not documented
76 : undef;
77  
78 # for any existing handles
79 0 ▶ DBI->visit_handles(sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
80 0 shift->{Profile} = $DBI::shared_profile;
81 0 return 1; # keep going to visit all
82 0 });
83  
84 0 return $DBI::shared_profile;
85 }
86  
87  
88 1 1;
89 __END__
↑ Summary