Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Is there any way to report mem usage?

by Anonymous Monk
on Feb 20, 2001 at 12:03 UTC ( #59612=categorized question: print w/replies, xml ) Need Help??
Contributed by Anonymous Monk on Feb 20, 2001 at 12:03 UTC
Q&A  > debugging


I would like to report memory usage to a log file at different points in a large perl script. Any suggestions (other than using "top" would be greatly appreciated). jarret

Answer: Is there any way to report mem usage?
contributed by ryan

If you are meaning the memory used by your program then there was talk of this here

If you are talking of the system in general then I might do something crude like this with the /proc file system:

$meminfo=`cat /proc/meminfo | grep "^Mem: "`; $meminfo =~ s/^Mem\:\W+//; ($total, $used, $free, $shared, $buffered, $cached) = split(/\W+/,$mem +info,6);

Then you have the 2nd line of /proc/meminfo in 6 variables and can write them out to whatever log you want. There are modules to deal with /proc but I can't find anything to return memory information, only individual process attributes.

I'm not fantastic at coding, just thought I'd give it a try, I'm sure there is a quicker way - but that is how I would do it with my current knowledge :) I guess this could break if the format of /proc/meminfo was ever changed.

Answer: Is there any way to report mem usage?
contributed by salva

You can use Proc::ProcessTable to get information about processes including their memory usage (VSize).

Recently I have also uploaded to CPAN Memchmark, a module that lets measure memory consumption for different algorithms comparing the results, though it is still a very early release.

Answer: Is there any way to report mem usage?
contributed by cmeyer

The module GTop may be useful to you. The excellent Apache::VMonitor makes use of it for monitoring mod_perl memory usage.

Be aware that it relies libgtop, a library that is part of the gnome desktop system. This library is not installed on my stock SuSE 9.2 (which uses kde by default). You must have gnome installed, but it is not necessary to run it.

Sadly, the documentation for GTop is substandard. Look to Apache::VMonitor for better usage examples.

Please (register and) log in if you wish to add an answer

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others romping around the Monastery: (8)
    As of 2018-07-20 20:49 GMT
    Find Nodes?
      Voting Booth?
      It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

      Results (441 votes). Check out past polls.