in reply to How to tell if script sucks...memory

If you want to check your memory use at several places in your program while it runs, this snippet provides a useful function to return how much memory you're using if you're on a *nix system.

Sadly, this doesn't port to systems that lack a procfs.
sub memsize { open(FH, '/proc/self/status'); while(<FH>) { return $_ if /^VmSize/; } close FH; }

Replies are listed 'Best First'.
Re^2: How to tell if script sucks...memory
by kyle (Abbot) on Feb 02, 2007 at 21:37 UTC

    I've used this:

    sub my_mem { my @pslines = grep( m{ \A \s* (?: \d+ \s+ ){2} $$ \b }xms, `ps axl` ); die if ( scalar @pslines != 1 ); my $line = $pslines[0]; chomp $line; my @words = split /\s+/, $line; return $words[6]; }

    It relies on the system's ps axl, not procfs. You can also use Devel::Size to size up individual data structures at run time.