Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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

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

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2022-09-26 19:42 GMT
Find Nodes?
    Voting Booth?
    I prefer my indexes to start at:

    Results (118 votes). Check out past polls.