Adam Kennedy's method for checking perl module memory usage

markjugg on 2007-03-03T14:58:31

I wanted to know: How much memory is my perl module consuming? Adam Kennedy had several times referenced the memory size of Perl modules, so I asked him how he figured it out. Here's the recipe he was kind enough to share, which I've reworked and embellished a bit for clarity:

Use ps.

> perl -de 1
> use Dependency::Of::YourMod::One;
> use Dependency::Of::YourMod::Two;

Then ps the process:

ps -O rss,vsz | grep 'perl -de'
The second and third numbers you'll see are the resident and virtual memory size.

> use YourMod;
Then ps the process again:

ps -O rss,vsz | grep 'perl -de'
That difference covers the needs of the module itself, and ignores the dependencies.

Now, that assumes that all your initialization runs at compile-time. If you have a singleton implementation you might need to create one to get the full module use.


A minor addition

Alias on 2007-03-04T19:25:31

I'll note that there's going to be some level of bloat from being in the debugger, but I've found it's generally close enough to be useful.