From 338f2b80610a33ae7e50f14978a80e11de7a9d6a Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Wed, 12 Feb 2014 04:36:11 +0100 Subject: get_mem: return a hashref instead of an array --- lib/VServer.pm | 42 ++++++++++++++++++++++++++++++------------ 1 file 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 Return memory information for the vserver specified by the given -context id. The function read the B file inside the I +context id. The function reads the B file inside the I directory of the vserver, parses the memory information and -multiplies it with the pagesize. The function returns four values -in the following order I, I, -I and I or B if -any error occurs. +multiplies it with the pagesize. The function returns a hashref with +the following values or B if any error occurs: + +=over + +=item C + +I + +=item C + +I + +=item C + +I + +=item C + +I + +=back =back -- cgit v1.2.3-1-g7c22