ted_pedersen wrote on 10/21/09 7:46 PM:

> But, I really don't want to start modifying code to do this...I'd rather
> be able to do something like you can do with execution time, which just
> involves using a command line option...
> 
> perl -d:DProf myprogram.pl
> dprofpp
> 
> And then you get a nice report like this, which shows where your program
> spent its time.
> 

I've recently converted to NYTProf:

http://search.cpan.org/~timb/Devel-NYTProf-2.10/

which leaps light years over the tried-and-true DProf tool.

> 
> So I want to do the same thing with memory, that is find out where my
> programs are spending their memory...
> 

http://perl.active-venture.com/pod/perldebguts-perlmemory.html

might prove useful.

> The closest I've come so far is actually not a Perl specific tool, but
> is rather a generic performance monitoring tool (available on Linux at
> least...) called valgrind, found at
> 
> http://valgrind.org <http://valgrind.org>
> 
> It's also available via apt-get ...
> 
> apt-get install valgrind
> 
> I'm not entirely certain what it's giving me though, so I'm still looking.

valgrind is very useful for finding mem leaks, but I haven't found it as helpful
for profiling. iirc, it also requires that your Perl is compiled with some
special flags.

Steven Lembark gave an interesting talk at Frozen Perl this year about memory
management with Perl. What I took away was "use arrays not hashes" if you are
trying to squeeze more out of Perl. I don't see slides but the talk is described
here:

http://www.frozen-perl.org/mpw2009/talk/1607

In general, though, having spent some significant time recently profiling some
of my own CPAN modules, I wonder why you are concerned about memory use. It's
Perl. Memory use sucks. :) Or are you simply running out of memory in some cases
and trying to figure out where to cut back?

NYTProf is excellent in any case, and might provide some clues.

I've been in touch with MSI about teaching a special Perl class next semester,
and I've been thinking of talking about something along this same topic, i.e.,
how to profile and optimize your Perl code, with particular examples using
NYTProf and then rewriting hot spots in C/XS (where of course memory usage is
moreorless under your own control). So if you do find useful ways of measuring
memory usage specifically, I would be very interested to hear.



-- 
Peter Karman  .  http://peknet.com/  .  [email protected]

Reply via email to