summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2014-02-12 04:36:11 +0100
committerAlexander Sulfrian <alexander@sulfrian.net>2014-02-12 04:36:11 +0100
commit338f2b80610a33ae7e50f14978a80e11de7a9d6a (patch)
treef170113662fbbe93237a53782e8ebf734f54e8fc
parenta1052aea4c790463f400d30c1fc5f45650d95bbc (diff)
downloadvserver-perl-338f2b80610a33ae7e50f14978a80e11de7a9d6a.tar.gz
vserver-perl-338f2b80610a33ae7e50f14978a80e11de7a9d6a.tar.bz2
vserver-perl-338f2b80610a33ae7e50f14978a80e11de7a9d6a.zip
get_mem: return a hashref instead of an array1.7
-rw-r--r--lib/VServer.pm42
1 files changed, 30 insertions, 12 deletions
diff --git a/lib/VServer.pm b/lib/VServer.pm
index 20c8cc1..4f19b2f 100644
--- a/lib/VServer.pm
+++ b/lib/VServer.pm
@@ -1,7 +1,7 @@
#!/usr/bin/perl -T
package VServer;
-our $VERSION = '1.6';
+our $VERSION = '1.7';
use strict;
use warnings;
@@ -99,26 +99,26 @@ sub get_mem($) {
my $context = shift;
my $dir = get_proc_dir($context) || return undef;
my $ps = POSIX::sysconf(&POSIX::_SC_PAGESIZE) || return undef;
- my @mem = undef;
+ my %mem = undef;
open(my $limit, "<", "$dir/limit") || return undef;
while (<$limit>) {
if ($_ =~ m/^VM:\s*([0-9]+)\s/) {
- $mem[0] = $1 * $ps;
+ %mem{'vm'} = $1 * $ps;
}
elsif ($_ =~ m/RSS:\s*([0-9]+)\s/) {
- $mem[1] = $1 * $ps;
+ $mem{'rss'} = $1 * $ps;
}
elsif ($_ =~ m/ANON:\s*([0-9]+)\s/) {
- $mem[2] = $1 * $ps;
+ $mem{'anon'} = $1 * $ps;
}
elsif ($_ =~ m/VML:\s*([0-9]+)\s/) {
- $mem[3] = $1 * $ps;
+ $mem{'vml'} = $1 * $ps;
}
}
close($limit);
- return @mem;
+ return \%mem;
}
1;
@@ -191,12 +191,30 @@ if any error occurs.
=item B<get_mem($context)>
Return memory information for the vserver specified by the given
-context id. The function read the B<limit> file inside the I</proc>
+context id. The function reads the B<limit> file inside the I</proc>
directory of the vserver, parses the memory information and
-multiplies it with the pagesize. The function returns four values
-in the following order I<virtual memory>, I<resident set size>,
-I<anonymous memory> and I<virtual locked memory> or B<undef> if
-any error occurs.
+multiplies it with the pagesize. The function returns a hashref with
+the following values or B<undef> if any error occurs:
+
+=over
+
+=item C<vm>
+
+I<virtual memory>
+
+=item C<rss>
+
+I<resident set size>
+
+=item C<anon>
+
+I<anonymous memory>
+
+=item C<vml>
+
+I<virtual locked memory>
+
+=back
=back