total memory usage of process
szabgab
created: 2006-09-05 08:52:02
It seems there is a memory leak in the C part of Net::RawIP while running on Solaris 8 with ActivePerl 5.8.6. As it turnes out I think I happened to fixed it by free-ing some memory that was mallocated...

Anyway I would like to write a test running the relevant function in a loop and checking the total memory use of my script before and after. I would like to do it in some platform independent way (at least among Unix/Linux and the like) and preferable to have it in a Perl module so I can just write a simple test.

Is there any module out there to report total memory usage of the current script? If not what tool is there to do it?

Update:
Thanks to McDarren I found Proc::ProcessTable that solved the problem.

Re: total memory usage of process
created: 2006-09-05 09:01:17
I'm not sure if either of these are exactly what you are looking for, but Test::Memory::Cycle looks interesting, as does Memchmark..
Re^2: total memory usage of process
created: 2006-09-05 09:31:19
The first one is for existing perl variables, not relevant in my case. Memchmark is promising, especially the Proc::ProcessTable module it is using internally.
Re: total memory usage of process
created: 2006-09-05 09:34:22
look in /proc/ for a file called 'stat' under a directory with the pid id of the process. Open it he 22nd field (starting at 0) is the amount of 4k memory pages used. We used to do it this way on Debian and I think it’s fairly standard for Linux, but I’m digging the 22nd field out from my (very leaky) memory. Example
#!/usr/bin/perl -w
use strict;
use FileHandle;

my $pid = $$;
my $fh = FileHandle->new(";
chomp $data;
$fh->close;

my @procinfo = split(/\s+/,$data);

print "$$ memory = ",$procinfo[22] ," bytes\n";
Re: total memory usage of process
created: 2006-09-05 10:25:38
In addition to banger's stat suggestion, if you are running X, I use a personal tool called MeM, which displays a little Tk window in the corner of the screen, with the current usage. See node 336856

I'm not really a human, but I play one on earth. Cogito ergo sum a bum

perlmonks.org content © perlmonks.org and bangers, McDarren, szabgab, zentara

prlmnks.org © 2006 edmund von der burg (eccles & toad)

v 0.03