| 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
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 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__ | ||||||||||