Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Memory Profiling

by pjf (Curate)
on Jul 05, 2005 at 06:44 UTC ( [id://472366]=perlquestion: print w/replies, xml ) Need Help??

pjf has asked for the wisdom of the Perl Monks concerning the following question:

Good day wise monks. I've had the same question asked of me twice in one day, and I've been shamed by the little knowledge and advice I could provide. In order to correct this state of ignorance, I'm hoping to gather any hints and tips that others may have discovered on the matter of memory profiling in Perl.

Perl comes with some excellent time code profiling tools. Devel::DProf is a simple and effective solution to find what subroutines and statements are using the most time. However profiling memory is another matter. Devel::Profile is an excellent way to discover which parts of one's code is being executed, and which are not.

Unfortunately, profiling memory is a difficult task. Code is simple to understand: it executes one line at a time, and is broken up into a larger chunks called subroutines. A regular profiler times each line, or each subroutine, and then a post-processing tool provides a useful summary at the end.

Memory is a different beast. Variables will be shared between multiple lines of code, and built into large structures that may be referenced from multiple locations. These can grow and shrink during a program execution, and not all variables will have names: many are nameless, and only accessed using references.

Perl has Dan Sugalski's Devel::Size, which appears to do an excellent job of reporting memory usage of individual variables as well as more complex data structures. It's good for when one suspects a certain variable is getting a little too large, but does not provide a way to gain a snapshot into Perl's overall memory usage.

Does anyone have any experiences, good or bad, with memory profiling tools for Perl? I'm not after hints to reduce memory usage, but instead tools or processes to gain an insight into the memory usage of a running Perl program.

Many thanks,

Replies are listed 'Best First'.
Re: Memory Profiling
by redhotpenguin (Deacon) on Jul 05, 2005 at 07:24 UTC
    Perl has Dan Sugalski's Devel::Size, which appears to do an excellent job of reporting memory usage of individual variables as well as more complex data structures. It's good for when one suspects a certain variable is getting a little too large, but does not provide a way to gain a snapshot into Perl's overall memory usage.

    If you're looking to determine an aggregate size for your program perhaps taking a look at the guts of Apache::SizeLimit might yield some useful techniques.

    perrin wrote that module IIRC, and it has some methods for returning process sizes on different platforms.

Re: Memory Profiling
by salva (Canon) on Jul 05, 2005 at 07:46 UTC
    take a look at Memchmark.

    It can measure memory comsumption for diferent algorithms, though it only gives you aproximate meassures

Re: Memory Profiling
by borisz (Canon) on Jul 05, 2005 at 07:42 UTC
    Take a look at valgrind for a overall memory statistic and much more. A really cool tool.
    Boris
Re: Memory Profiling
by adrianh (Chancellor) on Jul 05, 2005 at 13:19 UTC

    GTop might also be of use.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://472366]
Approved by Corion
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-03-19 05:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found