in reply to Finding the size of a variable

Awesome, but... what I'd really like is a general memory usage profiler. Given a Perl program I'd like to be able to examine memory allocation traces using something like dprofpp (mprofpp?).

I can't even begin to express how useful this would be. I also have absolutely no idea how to build it. But maybe you do? If the answer is yes, but you don't have the time to code it, I would be happy to do the grunt work!

-sam

Replies are listed 'Best First'.
Re: Re: Finding the size of a variable
by Elian (Parson) on Nov 11, 2002 at 19:36 UTC
    Try building with perl's malloc and -DDEBUGGING enabled. Ilya's wedged an amazing amount of tracking data into that memory allocator. Probably not quite enough to do what you want, but it's close. Unfortunately anything you might want to do will definitely require a custom perl, as you'd need to override the allocation and free routines. (This module has the advantage of being able to work standaline, as it doesn't have to intercept anything)
      Thanks, I'll try that. While awaiting your reply I had a minor brainstorm on how to build it. I could augment Devel::DProf (and/or my baby, Devel::Profiler) to capture the value of Devel::Size::total_size() at each data point. Use that to develop total memory allocation profiles for each subroutine. This would probably be effective at catching really large allocations, but it will likely miss small ones due to Perl's use of SV arenas, right?

      UPDATE: I'm dumb. I jumped to the wrong conclusion that Devel::Size::total_size() returned the total amount of allocated memory for Perl. RTFM, sam.

      -sam

        Oh, OK, I see. Hrm. Well, potentially, if the CV tracing worked properly, you could just do a total_size(\%main::); and watch the changes, as there's very little not findable from there. (Some of perl's internal structs are about it)

        Might be just a little CPU-intensive, though... :)