For example something that can tell me how many scalars, and estimate their data size + Perl overheads on a per-package basis in bytes?
You could put Elian's Devel::Size to good use. Something like this might be of help
use strict; use Devel::Size qw(size total_size); sub mem_size { my($pkg, $type) = @_; die("mem_size(): unknown variable type '$type'\n") if $type !~ /^(?: HASH | ARRAY | SCALAR )\z/x; my $ret = 0; no strict 'refs'; for(values %{"${pkg}::"}) { $ret += ( $type eq 'SCALAR' ? size( ${ *$_{$type} } ) : total_size( *$_{$type} ) ) if defined *$_{$type}; } return $ret; } print "SCALAR mem usage in main:: is ", mem_size("main", "SCALAR"), $/; __output__ SCALAR mem usage in main:: is 2098
Or even better something that can take a nested data structure and summarise how much data + overhead (hash buckets, key arrays?) is being used at a specified depth?
Again you could use Devel::Size for this task by employing total_size() at the desired depth. Also a hash in scalar context will return the number of used buckets and the number of allocated buckets (see. perldata).
Or code analysis tools that let me know about long lived large data structures that are not referenced again?
Data structures that are no longer referenced will be garbage-collected so you needn't worry about that.
Does releasing a hash make the recovered memory available to subsequent Perl structures?
That it does. Once a variable has been 'released' it's memory is then available to future variables so perl won't just keep on growing.
HTH

_________
broquaint


In reply to Re: How do I dumping Perls memory usage? by broquaint
in thread How do I dumping Perls memory usage? by jaa

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.