File Coverage

blib/lib/Plack/Middleware/Debug/Memory.pm
Criterion Covered Total %
statement 25 25 100.0
branch n/a
condition n/a
subroutine 8 8 100.0
pod 1 3 33.3
total 34 36 94.4


line stmt bran cond sub pod time code
1             package Plack::Middleware::Debug::Memory;
2 2     2   951 use 5.008;
  2         8  
3 2     2   10 use strict;
  2         5  
  2         51  
4 2     2   10 use warnings;
  2         4  
  2         72  
5 2     2   10 use parent qw(Plack::Middleware::Debug::Base);
  2         3  
  2         10  
6             our $VERSION = '0.17';
7              
8             sub run {
9 3     3 1 10 my($self, $env, $panel) = @_;
10              
11 3         18 my $before = $self->current_memory;
12              
13             return sub {
14 3     3   23 my $res = shift;
15              
16 3         11 my $after = $self->current_memory;
17 3         108 $panel->nav_subtitle($self->format_memory($after));
18              
19 3         77 $panel->content(
20             $self->render_list_pairs(
21             [ Before => $self->format_memory($before),
22             After => $self->format_memory($after),
23             Diff => $self->format_memory($after - $before) ],
24             ),
25             );
26 3         172 };
27             }
28              
29             sub format_memory {
30 12     12 0 66 my ($self, $memory) = @_;
31 12         269 1 while $memory =~ s/^([-+]?\d+)(\d{3})/$1,$2/;
32 12         317 return "$memory KB";
33             }
34              
35             sub current_memory {
36 6     6 0 14 my $self = shift;
37 6         52034 my $out = `ps -o rss= -p $$`;
38 6         327 $out =~ s/^\s*|\s*$//gs;
39 6         153 $out;
40             }
41              
42             1;
43             __END__