Good day wise monks. I've had the same question asked of me twice in one day, and I've been shamed by the little knowledge and advice I could provide. In order to correct this state of ignorance, I'm hoping to gather any hints and tips that others may have discovered on the matter of memory profiling in Perl.

Perl comes with some excellent time code profiling tools. Devel::DProf is a simple and effective solution to find what subroutines and statements are using the most time. However profiling memory is another matter. Devel::Profile is an excellent way to discover which parts of one's code is being executed, and which are not.

Unfortunately, profiling memory is a difficult task. Code is simple to understand: it executes one line at a time, and is broken up into a larger chunks called subroutines. A regular profiler times each line, or each subroutine, and then a post-processing tool provides a useful summary at the end.

Memory is a different beast. Variables will be shared between multiple lines of code, and built into large structures that may be referenced from multiple locations. These can grow and shrink during a program execution, and not all variables will have names: many are nameless, and only accessed using references.

Perl has Dan Sugalski's Devel::Size, which appears to do an excellent job of reporting memory usage of individual variables as well as more complex data structures. It's good for when one suspects a certain variable is getting a little too large, but does not provide a way to gain a snapshot into Perl's overall memory usage.

Does anyone have any experiences, good or bad, with memory profiling tools for Perl? I'm not after hints to reduce memory usage, but instead tools or processes to gain an insight into the memory usage of a running Perl program.

Many thanks,


In reply to Memory Profiling by pjf

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.