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

I'd like to get a good idea of how much additional memory a forked perl process is using after it is forked from its parent.

I can't just us the 'ps' command because the reported SHARE value is very inaccurate.

All I need to do is to instrument malloc() and free(). Every time malloc() is called (and is successful) increment an accumulator, and every time free() is called, decrement the accumulator accordingly.

Any ideas of how to do this? One idea is to replace the malloc/free routines in the C library (like with LD_PRELOAD), but I've heard that perl can/does implement it's own memory management on top of malloc() and free() so that this may have to be done inside the perl interperter.

Thanks!

  • Comment on detrmining the amount of memory a perl process is using

Replies are listed 'Best First'.
Re: detrmining the amount of memory a perl process is using
by zwon (Abbot) on Jan 26, 2010 at 19:51 UTC

    Note, that malloc and especially free not always change amount of memory allocated to process. Have a look on valgrind and dmalloc if you're debugging memory allocation.

Re: detrmining the amount of memory a perl process is using
by foolishmortal (Novice) on Jan 27, 2010 at 15:08 UTC

    This thread might throw some light on what you are trying to do.

    If you are profiling this sort of thing for your own personal knowledge, dmalloc or valgrind might be the way to go.

    If you are trying to do this sort of thing inside an application (maybe monitoring a set of processes and throttling their ability to run dynamically based on memory footprint) then the technique in the thread is probably the way to go, as the overhead of the instrumentation can substantially slow the runtime of the profiled process.