line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test2::Plugin::MemUsage; |
2
|
1
|
|
|
1
|
|
70565
|
use strict; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
23
|
|
3
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
32
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.002001'; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
4
|
use Test2::API qw/test2_add_callback_exit/; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
348
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
my $ADDED_HOOK = 0; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub import { |
12
|
1
|
50
|
|
1
|
|
24
|
return if $ADDED_HOOK++; |
13
|
|
|
|
|
|
|
|
14
|
1
|
|
|
|
|
2
|
test2_add_callback_exit(\&send_mem_event); |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
1
|
|
|
1
|
|
16505
|
sub proc_file { "/proc/$$/status" } |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub send_mem_event { |
20
|
1
|
|
|
1
|
0
|
444
|
my ($ctx, $real, $new) = @_; |
21
|
|
|
|
|
|
|
|
22
|
1
|
|
|
|
|
4
|
my $file = proc_file(); |
23
|
1
|
50
|
|
|
|
23
|
return unless -f $file; |
24
|
|
|
|
|
|
|
|
25
|
1
|
|
|
|
|
2
|
my $stats; |
26
|
|
|
|
|
|
|
{ |
27
|
1
|
50
|
|
|
|
3
|
open(my $fh, '<', $file) or die "Could not open file '$file' (<): $!"; |
|
1
|
|
|
|
|
35
|
|
28
|
1
|
|
|
|
|
5
|
local $/; |
29
|
1
|
|
|
|
|
25
|
$stats = <$fh>; |
30
|
1
|
50
|
|
|
|
15
|
close($fh) or die "Could not close file '$file': $!"; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
1
|
50
|
|
|
|
3
|
return unless $stats; |
34
|
|
|
|
|
|
|
|
35
|
1
|
|
|
|
|
3
|
my %mem; |
36
|
1
|
50
|
|
|
|
14
|
$mem{peak} = [$1, $2] if $stats =~ m/VmPeak:\s+(\d+) (\S+)/; |
37
|
1
|
50
|
|
|
|
8
|
$mem{size} = [$1, $2] if $stats =~ m/VmSize:\s+(\d+) (\S+)/; |
38
|
1
|
50
|
|
|
|
10
|
$mem{rss} = [$1, $2] if $stats =~ m/VmRSS:\s+(\d+) (\S+)/; |
39
|
1
|
|
|
|
|
5
|
$mem{details} = "rss: $mem{rss}->[0]$mem{rss}->[1]\nsize: $mem{size}->[0]$mem{size}->[1]\npeak: $mem{peak}->[0]$mem{peak}->[1]"; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
$ctx->send_ev2( |
42
|
|
|
|
|
|
|
memory => \%mem, |
43
|
|
|
|
|
|
|
about => {package => __PACKAGE__, details => $mem{details}}, |
44
|
1
|
|
|
|
|
11
|
info => [{tag => 'MEMORY', details => $mem{details}}], |
45
|
|
|
|
|
|
|
); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
1; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
__END__ |