On Tue, Mar 8, 2011 at 7:52 PM, Tom Metro <[email protected]> wrote:
> Some code I'm working on is triggering an out of memory error, and I'd
> like to figure out what specifically is responsible. (It's a complex
> system with dozens of libraries and it runs in parallel across a cluster
> of machines. Running the code in a debugger isn't a practical option.)
>
> Any recommendation for tools to do this?

Devel::Leak and Devel::LeakTrace are my best suggestion.

> I don't recall if the typical profiling tools record memory usage, but a
> traditional profiler would be overkill for what I need.
>
> The ideal solution would be something that could hook the OOM exception
> and dump the symbol table along with stats for how much memory each
> symbol is occupying. Another useful possibility would be dumping the
> call stack.

The symbol table is not enough.  It doesn't see data in lexical
variables.  And figuring out how much memory an array or hash may be
taking is easier said than done, because doing it means walking the
array or hash and figuring that out.  But with circular data
structures you have to keep track of where you have been, which
requires somewhere to stick that information, but you're already out
of memory.

> Is it possible to trap the OOM error? I don't think a __DIE__ handler
> catches it. It seems to be an unusual error in that you often see
> multiple of them, as if the first few are warnings, and then eventually
> it is fatal.

Random possibilities.  Could it be that Perl not always check whether
it got memory when asked?  So you don't crash until you ask for memory
somewhere that checked properly.

Or perhaps Perl doesn't exit on asking for memory, but crashes when it
tries to use memory it doesn't have.

Either way I think you are better off inserting things that drop debug
state every so often, and then figure out what is growing, and try to
narrow it down.  Devel::Leak and friends are good for this.  If you
are constantly growing memory usage, this can help figure out why.

Good luck.

_______________________________________________
Boston-pm mailing list
[email protected]
http://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to