File Coverage

blib/lib/Linux/MemInfo.pm
Criterion Covered Total %
statement 12 33 36.3
branch 0 8 0.0
condition n/a
subroutine 4 5 80.0
pod 0 1 0.0
total 16 47 34.0


line stmt bran cond sub pod time code
1             package Linux::MemInfo;
2              
3 1     1   94257 use 5.006;
  1         10  
  1         85  
4 1     1   8 use strict;
  1         2  
  1         44  
5 1     1   6 use warnings;
  1         8  
  1         86  
6              
7             require Exporter;
8 1     1   10160 use AutoLoader qw(AUTOLOAD);
  1         3248  
  1         8  
9              
10             our @ISA = qw(Exporter);
11              
12             # Items to export into callers namespace by default. Note: do not export
13             # names by default without a very good reason. Use EXPORT_OK instead.
14             # Do not simply export all your public functions/methods/constants.
15              
16             # This allows declaration use Linux::MemInfo ':all';
17             # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
18             # will save memory.
19             our %EXPORT_TAGS = ( 'all' => [ qw( get_mem_info
20             ) ] );
21              
22             our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
23              
24             our @EXPORT = qw( get_mem_info
25             );
26              
27             our $VERSION = '0.03';
28              
29              
30             # Preloaded methods go here.
31              
32             # Autoload methods go after =cut, and are processed by the autosplit program.
33              
34             sub get_mem_info() {
35 0     0 0   my %mem;
36 0 0         open(INFIL,"/proc/meminfo") || die("Unable To Open /proc/meminfo\n");
37 0           NXTMI: foreach() {
38 0 0         if( m/^Mem:\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)/ ) {
    0          
    0          
39 0           $mem{mem_total} = $1;
40 0           $mem{mem_used} = $2;
41 0           $mem{mem_free} = $3;
42 0           $mem{mem_shared} = $4;
43 0           $mem{mem_buffers} = $5;
44 0           $mem{mem_cached} = $6;
45 0           next NXTMI;
46             }
47             elsif( m/^Swap:\s+(\S+)\s+(\S+)\s+(\S+)/ ) {
48 0           $mem{swap_total} = $1;
49 0           $mem{swap_used} = $2;
50 0           $mem{swap_free} = $3;
51 0           next NXTMI;
52             }
53             elsif( m/^(\S+):\s+(\S+) (\S+)/ ) {
54 0           my $unit = $1 . "Unit";
55 0           $mem{$1} = $2;
56 0           $mem{$unit} = $3;
57 0           next NXTMI;
58             }
59             }
60 0           close(INFIL);
61 0           return %mem
62             }
63              
64              
65             1;
66             __END__