Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Is there any way to report mem usage?

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


Description:

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!
  • 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
  • Outside of code tags, you may need to use entities for some characters:
            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?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others contemplating the Monastery: (6)
    As of 2014-08-02 08:52 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      Who would be the most fun to work for?















      Results (55 votes), past polls