szabgab has asked for the wisdom of the Perl Monks concerning the following question:

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.

Replies are listed 'Best First'.
Re: total memory usage of process
by McDarren (Abbot) on Sep 05, 2006 at 13:01 UTC
      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
by bangers (Pilgrim) on Sep 05, 2006 at 13:34 UTC
    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("</proc/$pid/stat"); my $data = <$fh>; chomp $data; $fh->close; my @procinfo = split(/\s+/,$data); print "$$ memory = ",$procinfo[22] ," bytes\n";
Re: total memory usage of process
by zentara (Cardinal) on Sep 05, 2006 at 14:25 UTC
    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 linux memory leak monitor

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