I'm trying to profile my application's memory usage, but it's not working. Basically, I just want to list all variables, sorted on which uses the most memory. This is the current function I've developed, but it doesn't work. It hangs, and I cannot quite understand why.
sub profile_memory { use Devel::Gladiator (); use Devel::Size (); use Data::Dumper qw(Dumper); use Scalar::Util (); open(my $fh,">>/tmp/memory_profile_$$.log"); my $all=Devel::Gladiator::walk_arena(); my $size_hash={}; foreach my $sv ( @$all ) { next if Scalar::Util::refaddr($sv) == Scalar::Util::refaddr($a +ll); next if Scalar::Util::refaddr($sv) == Scalar::Util::refaddr($s +ize_hash); next if Scalar::Util::refaddr($sv) == Scalar::Util::refaddr($f +h); next if ref($sv) eq 'GLOB'; # Devel::Size segfaults on this my $size=0; eval { #warn(ref($sv)) unless ref($sv) eq 'SCALAR'; $size=Devel::Size::size($sv); #$size=Scalar::Util::refaddr($sv); }; next if $@; my $sv_list=$size_hash->{$size} || []; next if Scalar::Util::refaddr($sv) == Scalar::Util::refaddr($s +v_list); push @$sv_list, $sv; $size_hash->{$size}=$sv_list; } print $fh ( "-" x 80 ) . "\n"; # print $fh Dumper($size_hash); foreach my $size ( sort { $b <=> $a } keys %$size_hash ) { foreach my $size ( keys %$size_hash ) { print $fh $size . '=['; foreach my $sv ( @{ $size_hash->{$size} } ) { print $fh ref($sv) . ", "; } print $fh ']' . "\n"; } close($fh); return 1; }

In reply to Trying to profile my app's memory usage by robins

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.