| 1 | package Plack::Middleware::Debug::LWP; | ||
| 2 | 1 | $Plack::Middleware::Debug::LWP::VERSION = '0.3'; | |
| 3 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | |||
| 6 | 1 | ▶ | use LWPx::Profile; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | 1 | ▶ | use parent qw(Plack::Middleware::Debug::Base); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | |||
| 9 | =head1 NAME | ||
| 10 | |||
| 11 | Plack::Middleware::Debug::LWP - LWP Profiling Panel | ||
| 12 | |||
| 13 | =head1 VERSION | ||
| 14 | |||
| 15 | version 0.3 | ||
| 16 | |||
| 17 | =head1 SYNOPSIS | ||
| 18 | |||
| 19 | enable 'Debug::LWP'; | ||
| 20 | |||
| 21 | =head1 DESCRIPTION | ||
| 22 | |||
| 23 | This module provides a panel for the L<Plack::Middleware::Debug> that gives | ||
| 24 | profiling information for L<LWP::UserAgent> requests. | ||
| 25 | |||
| 26 | =cut | ||
| 27 | |||
| 28 | |||
| 29 | |||
| 30 | 1 | my $lwp_template = __PACKAGE__->build_template(<<'ENDOFIT'); | |
| 31 | <table> | ||
| 32 | <thead> | ||
| 33 | <tr> | ||
| 34 | <th>Request</th> | ||
| 35 | <th>Timing</th> | ||
| 36 | </tr> | ||
| 37 | </thead> | ||
| 38 | <tbody> | ||
| 39 | % my $i; | ||
| 40 | % while (@{$_[0]->{list}}) { | ||
| 41 | % my($key, $value) = splice(@{$_[0]->{list}}, 0, 2); | ||
| 42 | <tr class="<%= ++$i % 2 ? 'plDebugOdd' : 'plDebugEven' %>"> | ||
| 43 | <td><pre><%= $key %></pre></td> | ||
| 44 | <td><%= $value %></td> | ||
| 45 | </tr> | ||
| 46 | % } | ||
| 47 | </tbody> | ||
| 48 | </table> | ||
| 49 | ENDOFIT | ||
| 50 | |||
| 51 | |||
| 52 | 0 | ▶ | sub run { |
|
Subroutine
run: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 53 | 0 | my($self, $env, $panel) = @_; | |
| 54 | |||
| 55 | 0 | LWPx::Profile::start_profiling(); | |
| 56 | |||
| 57 | 0 | ▶ | return sub { |
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||
| 58 | 0 | my $res = shift; | |
| 59 | |||
| 60 | 0 | my $profile = LWPx::Profile::stop_profiling(); | |
| 61 | |||
| 62 | 0 | my @lines; | |
| 63 | 0 | my ($time, $requests); | |
| 64 | |||
| 65 | 0 | for my $req (sort { | |
| 66 | $profile->{$a}->{time_of_first_sample} <=> $profile->{$b}->{time_of_first_sample} | ||
| 67 | 0 | } keys %$profile) { | |
| 68 | 0 | my $stats = $profile->{$req}; | |
| 69 | 0 | my $summary = sprintf("%.5f/%d (%.5f avg)", $stats->{total_duration}, $stats->{count}, $stats->{total_duration} / $stats->{count}); | |
| 70 | 0 | push(@lines, $req, $summary); | |
| 71 | 0 | $requests += $stats->{count}; | |
| 72 | 0 | $time += $stats->{total_duration}; | |
| 73 | } | ||
| 74 | |||
| 75 | 0 | my $summary = sprintf("%d requests / %.2f seconds", $requests, $time); | |
| 76 | |||
| 77 | 0 | $panel->nav_title("LWP Requests"); | |
| 78 | 0 | $panel->title("LWP Requests ($summary)"); | |
| 79 | 0 | $panel->nav_subtitle($summary); | |
| 80 | |||
| 81 | 0 | $panel->content( | |
| 82 | $self->render($lwp_template, { list => \@lines }) | ||
| 83 | ); | ||
| 84 | 0 | }; | |
| 85 | } | ||
| 86 | |||
| 87 | |||
| 88 | |||
| 89 | =head1 TODO | ||
| 90 | |||
| 91 | =over 2 | ||
| 92 | |||
| 93 | =item * | ||
| 94 | |||
| 95 | The docs are pretty middling at the moment. | ||
| 96 | |||
| 97 | =back | ||
| 98 | |||
| 99 | =head1 AUTHORS | ||
| 100 | |||
| 101 | Chris Reinhardt | ||
| 102 | crein@cpan.org | ||
| 103 | |||
| 104 | Mark Ng | ||
| 105 | cpan@markng.co.uk | ||
| 106 | |||
| 107 | =head1 COPYRIGHT | ||
| 108 | |||
| 109 | This program is free software; you can redistribute | ||
| 110 | it and/or modify it under the same terms as Perl itself. | ||
| 111 | |||
| 112 | The full text of the license can be found in the | ||
| 113 | LICENSE file included with this module. | ||
| 114 | |||
| 115 | =head1 SEE ALSO | ||
| 116 | |||
| 117 | L<Plack::Middleware::Debug>, L<LWP::UserAgent>, L<LWPx::Profile>, perl(1) | ||
| 118 | |||
| 119 | =cut | ||
| 120 | |||
| 121 | 1 | 1; | |
| 122 | __END__ | ||