| 1 | package Linux::MemInfo; | ||||||||||||||||||
| 2 | |||||||||||||||||||
| 3 | 1 | ▶ | use 5.006; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 6 | |||||||||||||||||||
| 7 | 1 | require Exporter; | |||||||||||||||||
| 8 | 1 | ▶ | use AutoLoader qw(AUTOLOAD); | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 9 | |||||||||||||||||||
| 10 | 1 | 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 | 1 | our %EXPORT_TAGS = ( 'all' => [ qw( get_mem_info | |||||||||||||||||
| 20 | ) ] ); | ||||||||||||||||||
| 21 | |||||||||||||||||||
| 22 | 1 | our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); | |||||||||||||||||
| 23 | |||||||||||||||||||
| 24 | 1 | our @EXPORT = qw( get_mem_info | |||||||||||||||||
| 25 | ); | ||||||||||||||||||
| 26 | |||||||||||||||||||
| 27 | 1 | 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 | 0 | ▶ | sub get_mem_info() { | ||||||||||||||||
|
Subroutine
get_mem_info: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||
| 35 | 0 | my %mem; | |||||||||||||||||
| 36 | 0 | ▶ | open(INFIL,"/proc/meminfo") || die("Unable To Open /proc/meminfo\n"); | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 37 | 0 | NXTMI: foreach(<INFIL>) { | |||||||||||||||||
| 38 | 0 | ▶ | if( m/^Mem:\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)/ ) { | ||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||
| 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 | 1; | |||||||||||||||||
| 66 | __END__ | ||||||||||||||||||