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

Hello, all!

I wonder is there a way to get information from perl program on how much memory it eats?

It will be best to have a solution without recompiling a perl, for standard binary distribution, but I will recompile my installation of perl if that would be necessary.

I think it would be very helpful to have such information at hand in general, but especially useful when I'm trying to do something on my poor WinCE device.

Best wishes,
Vadim.

Replies are listed 'Best First'.
Re: Memory usage information
by tomhukins (Curate) on May 23, 2002 at 09:16 UTC

    I've never done anything like this on Windows, but a hunt around CPAN comes up with Win32::SystemInfo. If this doesn't meet your needs, why not use an external tool to monitor your process? Does WinCE have the Windows Task Manager, and if so would that be any use?

    In general, I'd recommend BSD::Resource for this, but I doubt it will work on WinCE.

      Thank you for interesting input, and sometimes your approach this will work good. But I am trying to find less platform-dependent (WinCE is just an example!) but rather Perl-specific solution, something similar to Devel::Prof or even DB::DB modules.

      I think best solution will be an XS module that understands Perl internals and provides information, but I am lost whether such exists, or can be written without changing the Perl core.

      BTW will BSD::Resource work for Linux? for Win32?

Re: Memory usage information
by mrbbking (Hermit) on May 23, 2002 at 11:45 UTC
    How to Calculate Memory Needs? has some related discussion.

    I ended up relying on the Windows Task Manager to monitor mine. Nobody mentioned a way to do it within the script, though. Sounds like *that* is what you want.

      Yes, that link has some related information, including
      (but not limited to :)
      - PERL_DEBUG_MSTATS
      - perl -V:d_mymalloc

      I will use those in my case.

      It's pity that perl does not have a possibility to acquire such information during execution (AFAIK, Java hase one, but I'm not sure). But I can live without that information provided I have great speed gains for ordinary programs execution :)
      Vadim

Re: Memory usage information
by svad (Pilgrim) on May 23, 2002 at 15:06 UTC
    After useful tips given to me, I've searched Perl distribution perl@16267 and found out that perl571delta.pod says:
    =item * Devel::Peek now has an interface for the Perl memory statistics (this works only if you are using perl's malloc, and if you have compiled with debugging).
    ... and Devel::Peek has similar explanations.

    So, if one interested in such statistic, (s?)he should recompile perl with debugging and perl-malloc options.

    A bit pity that this is not available in standard executables, or at least without -DDEBUGGING, but it is good to have such possibility at all.

    Many thanks to all who helped me with this,
    Vadim.