I'm trying to learn how to profile perl memory.
I have a very simple Perl hello-world script and I want to know its size in memory.
I use GTop utility to measure the memory (recommended in mod_perl book by Stas Beckman). GTop provides the results that confuse me.
When I run the script from the command line GTop says: 7M.
When I run it under mod_perl
, GTop says: 54M.
Why so much?!
Why script memory grows so much under mod_perl
?
Or maybe I measure the memory in a wrong way?
How do you profile perl script memory?
Here are the script and its output (I have added commas manually to easily read the numbers)
Run from command-line
> perl simple.pl size: 7,282688 share: 2,027520 diff: 5,255168
Run under mod_perl
size: 54,878208 share: 4,661248 diff: 50,216960
Script simple.pl
#!/usr/bin/perl
use strict;
use warnings;
use CGI ();
my $cgi = CGI->new;
print $cgi->header('text/plain');
use GTop;
print "Hello, world!\n";
my $m = GTop->new->proc_mem($$);
print "size: ".$m->size."\n";
print "share: ".$m->share."\n";
my $diff = $m->size - $m->share;
print "diff: $diff\n";