Outside of the perl world (and hence of little direct use to you), you have valgrind massif, which does pretty much what you ask. Memprof (if it is still working) and exmap (which is more focussed on fairly apportioning actually-used RAM amongst multiple processes, accounting for the vagaries of virtual memory).

Within perl, I have in the past written code which walks all package variables in all packages (I did it directly, starting at the %main:: hash, but there's probably a module to make that easier), using Devel::Size::total_size to work out the size of each. This worked well fairly well (sorry - I was unable to release it, but it was a fairly quick hack).

This approach would of course miss any leaked memory (which was no longer rooted in a package var) as well as anything only reachable via a lexical - although that might be fixable with PadWalker. It would also double-count any memory which was reachable via more than one place.

The code basically took a snapshot of all vars and sizes and then gave diffs against it on each subsequent invocation, looking for growing data structures over time.

It was all pure perl and I guess it wouldn't take more than a day or two to recreate from the above description.


In reply to Re: Profiling memory by jbert
in thread Profiling memory by kyle

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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, details, 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, summary, 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.