Devel::MemoryTrace::Light
2011-06-14 21:52:55 UTC
This is a little Perl module I wrote to figure out what was causing memory growth in some pretty large projects I was working on. It's fairly simple to use:
perl -d:MemoryTrace::Light ./program.pl
That will run program.pl under the perl debugger and print out a message when Perl requests more memory from the OS. This is done very simply by using GTop or BSD::Process to request the current program's resident set size after every line of execution. If it detects a change, it calls an overridable method which, by default, prints out a message to STDOUT.
There's a few configurable features (VIA an %ENV variable):
- Custom providers - Allows users to replace GTop/BSD::Process with their own providers
- Compile time profiling - Disabled by default. Allows tracing of 'use Some::Module'
As well as some run time control:
- enable/disable tracing on the fly - Uses Perl's $DB::single, so there's very little overhead when tracing is disabled
- set_callback/restore_callback - Allows users to replace the default behavior of printing to STDOUT when memory changes are detected
Hope you find it useful: Devel::MemoryTrace::Light on CPAN.
-- Matthew Horsfall (alh)