line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Devel::Memalyzer::Plugin::ProcSmaps; |
2
|
1
|
|
|
1
|
|
1498
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
37
|
|
3
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
39
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
7
|
use base 'Devel::Memalyzer::Base'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
643
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
BEGIN { |
8
|
1
|
50
|
|
1
|
|
370
|
die( __PACKAGE__ . ' cannot be used without a proc filesystem') |
9
|
|
|
|
|
|
|
unless -e '/proc'; |
10
|
|
|
|
|
|
|
} |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub collect { |
13
|
1
|
|
|
1
|
0
|
3
|
my $self = shift; |
14
|
1
|
|
|
|
|
3
|
my ( $pid ) = @_; |
15
|
|
|
|
|
|
|
|
16
|
1
|
|
|
|
|
3
|
return $self->capture_smaps( $pid ); |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub smaps { |
20
|
1
|
|
|
1
|
|
5
|
my $self = shift; |
21
|
1
|
|
|
|
|
2
|
my ( $pid ) = @_; |
22
|
1
|
|
|
|
|
8
|
return "/proc/$pid/smaps"; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub capture_smaps { |
26
|
1
|
|
|
1
|
0
|
2
|
my $self = shift; |
27
|
1
|
|
|
|
|
2
|
my ( $pid ) = @_; |
28
|
1
|
|
|
|
|
4
|
my $smaps_file = $self->smaps( $pid ); |
29
|
|
|
|
|
|
|
|
30
|
1
|
|
|
|
|
5
|
my %data; |
31
|
1
|
50
|
33
|
|
|
52
|
next unless -e $smaps_file && -r $smaps_file; |
32
|
1
|
50
|
|
|
|
50
|
open( my $smap, '<', $smaps_file ) || die( "Error opening smaps: $!" ); |
33
|
1
|
|
|
|
|
3
|
my $module; |
34
|
1
|
|
|
|
|
78
|
while( my $line = <$smap> ) { |
35
|
448
|
|
|
|
|
412
|
chomp( $line ); |
36
|
448
|
100
|
|
|
|
758
|
if ( $module ) { |
37
|
8
|
|
|
|
|
21
|
$line =~ m/^Size:\s+(\d+)/i; |
38
|
8
|
|
|
|
|
22
|
$data{ $module } += $1; |
39
|
8
|
|
|
|
|
7
|
$module = undef; |
40
|
8
|
|
|
|
|
21
|
next; |
41
|
|
|
|
|
|
|
} |
42
|
440
|
100
|
|
|
|
1327
|
next unless $line =~ m{(/lib/perl5/.*$)}; |
43
|
8
|
|
|
|
|
15
|
$module = $1; |
44
|
8
|
|
100
|
|
|
53
|
$data{ $module } ||= 0; |
45
|
|
|
|
|
|
|
} |
46
|
1
|
|
|
|
|
13
|
close( $smap ); |
47
|
1
|
|
|
|
|
32
|
return %data; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
1; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
__END__ |