NAME
Devel::Mallinfo -- mallinfo() memory statistics
SYNOPSIS
use Devel::Mallinfo;
my $hashref = Devel::Mallinfo::mallinfo();
print "uordblks used space ", $hashref->{'uordblks'}, "\n";
# or import into your namespace per Exporter
use Devel::Mallinfo ('mallinfo');
my $hashref = mallinfo();
DESCRIPTION
Devel::Mallinfo is an interface to the C library mallinfo function giving various totals for memory used by malloc. This is meant for development to give you an idea what your program and libraries is using.
Note malloc isn't the only way memory can be used. Program and library data and bss segments and the occasional direct mmap don't show up in mallinfo. Normally however almost all runtime space goes through malloc, so it's close to the total, and dynamic runtime usage is often what you're interested in anyway.
FUNCTIONS
$hashref = Devel::Mallinfo::mallinfo()-
Return a reference to a hash of the
struct mallinfovalues obtained frommallinfo. The keys are field name strings, and the values are integers. For example,{ 'arena' => 1234, 'uordblks' => 5678, ... }So to print (in no particular order),
my $info = Devel::Mallinfo::mallinfo(); foreach my $field (keys %$info) { print "$field is $info->{$field}\n"; }Field names are grepped out of
struct mallinfoat build time, so everything on your system should be available. Ifmallinfois not available in the particularmalloclibrary Perl is using thenDevel::Mallinfo::mallinforeturns a reference to an empty hash.
Fields
See the mallinfo man page, or the GNU C Library Reference Manual section "Statistics for Memory Allocation with `malloc'", for what the fields mean.
For reference, on a modern system arena plus hblkhd is the total memory taken from the system. hblkhd space is big blocks in use by the program. Within the arena space uordblks plus usmblks is currently in use, and fordblks plus fsmblks is free.
hblkhd space is returned to the system when freed. arena space may be reduced by shrinking when there's enough free blocks at its end to be worth doing. keepcost is the current free space at the end which could be given back.
OTHER NOTES
On a 64-bit system with a 32-bit C int type, the int fields in struct mallinfo might overflow (and wrap around to small or negative values). This is a known C library problem, which Devel::Mallinfo doesn't try to do anything about.
The mallopt function would be a logical companion to mallinfo, but generally it must be called before the first ever malloc, so anything in Perl is much too late.
HOME PAGE
http://user42.tuxfamily.org/devel-mallinfo/index.html
LICENSE
Devel-Mallinfo is Copyright 2007, 2008, 2009 Kevin Ryde
Devel-Mallinfo is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.
Devel-Mallinfo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Devel-Mallinfo. If not, see http://www.gnu.org/licenses/.
SEE ALSO
mallinfo(3)