in reply to Trying to profile my app's memory usage

It hangs,

That's scant information upon which to make a diagnosis.

You could try this version of Devel::Size. It uses far less memory and has much better trap handling than the official version. It'll probably allow you to do away with this:

next if ref($sv) eq 'GLOB'; # Devel::Size segfaults on this

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

Replies are listed 'Best First'.
Re^2: Trying to profile my apps memory usage
by robins (Acolyte) on Nov 19, 2008 at 12:49 UTC

    CPU activity is max (99%).

    Memory is stable (not climbing).

    walk_arena() finished.

    It's the printout loop that seems to hang. In fact it seems like it's the foreach (even without the sort) that hangs. The odd this is that if I try to use Data::Dumper to dump $size_hash it hangs too.

    Cannot determine it because the foreach seems to hang.

    I re-ran the tests with v0.72 of Devel::Size. Same result.

      Memory is stable (not climbing).

      How much is it using at that point?

      Best guess on the info so far is that you are running out of (physical) memory, and moving into swapping.

      One assumes that the reason you are profiling memory is because you are using a lot of it--prior to deciding to profile. If so, building a hash that contains a reference to every SV in your application is likely to at least quadruple the ammount of memory used. Then creating a list of all the keys of that hash:

      foreach my $size ( keys %$size_hash ) { ##.................^^^^^^^^^^^^^^^^

      is going to stretch that by (guess!) half as much again.

      If you use Data::Dumper on that same hash the memory requirement will likely quadruple again as it uses a hash internally (of the SV addresses), to detect circular and duplicate references.

      Your best bet, (based upon my wild guesswork above), would be to avoid building lists by iterating the hash using while each, and iterating the arrays using the range iterator (.. which doesn't build a list):

      while( my( $size, $ref ) = each %{ $size_hash } ) { print $fh $size . '=['; foreach my $i ( 0 .. $#{ $ref } ) { print $fh ref( $ref->[ $i ] ) . ", "; } print $fh ']' . "\n"; }

      That might just allow you to iterate through without breaking the memory bank and moving into swapping.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.