in reply to Allocated memory to Script

I added Memory::Usage to BrowserUk's script. Using it is simple. To start recording, do
$mu->record($your message here);
To stop, do
$mu->record->($msg here);
To insert the results at the end, there are a couple of ways that I like. I prefer "state()" which returns an arrayref.
#! perl -sl use strict; use warnings; use Memory::Usage; use Data::Dump qw(dump); my $mu = Memory::Usage->new(); $mu->record('start =>'); open FH, '<', $ARGV[0] or die "file not found"; my $line = 0; my %hash ; while( <FH> ) { $hash{ $line } = undef; $line++; } close FH; $mu->record('end =>'); print dump($mu->state());

Replies are listed 'Best First'.
Re^2: Allocated memory to Script
by BrowserUk (Patriarch) on Jul 08, 2011 at 12:42 UTC
    I added Memory::Usage to BrowserUk's script

    That's all very well, but as the module doesn't work on Windows, it is entirely useless.

      According to this, it does work on Windows.

        cygwin != Windows.

        # Returns # (vsize, rss, shared pages, code pages, data+stack pages) # in kilobytes. Precision is to nearest 4k page. # TODO: Proc::ProcessTable so that we can support non-Linux? my $page_size_in_kb = 4; sub _get_mem_data { my ($class, $pid) = @_; sysopen(my $fh, "/proc/$pid/statm", 0) or die $!; sysread($fh, my $line, 255) or die $!;

        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.