in reply to module memory usage

I have taked a look in the module B::Size, as our friend stvn pointed it, and based in a code of Apache::Status I made this function that prints a package size report:
package_size('main'); sub package_size { my($package) = shift ; require B::TerseSize ; print("Memory Usage for package $package\n\n"); my($subs, $opcount, $opsize) = B::TerseSize::package_size($package +); print("Totals: $opsize bytes | $opcount OPs\n\n"); my($clen, $slen, $nlen); my @keys = map { $nlen = length > $nlen ? length : $nlen; $_; } ( sort { $subs->{$b}->{size} <=> $subs->{$a}->{size +} } keys %$subs ); $clen = length $subs->{$keys[0]}->{count}; $slen = length $subs->{$keys[0]}->{size}; for my $name (@keys) { my $stats = $subs->{$name}; if ($name =~ /^my /) { printf "%-${nlen}s %${slen}d bytes\n", $name, $stats->{size} ; } else { printf "%-${nlen}s %${slen}d bytes | %${clen}d OPs\n", $name, +$stats->{size}, $stats->{count} ; } } }

And here's an output example:

Memory Usage for package main Totals: 24699 bytes | 212 OPs package_size 9526 bytes | 212 OPs *ENV{HASH} 3372 bytes | 0 OPs *SIG{HASH} 2943 bytes | 0 OPs *INC{HASH} 1378 bytes | 0 OPs *_{HASH} 228 bytes | 0 OPs *INC{ARRAY} 175 bytes | 0 OPs *_{ARRAY} 125 bytes | 0 OPs *0{SCALAR} 69 bytes | 0 OPs *1{SCALAR} 69 bytes | 0 OPs *ARGV{ARRAY} 60 bytes | 0 OPs *_{SCALAR} 26 bytes | 0 OPs

Enjoy!

Graciliano M. P.
"Creativity is the expression of the liberty".

Replies are listed 'Best First'.
Re: Re: module memory usage
by smackdab (Pilgrim) on Dec 22, 2003 at 23:05 UTC
    Very cool, I think it shows the size of the code loaded...I wonder if there is a way to get the runtime footprint?

    While Tk is worth every byte, It uses:
    Memory: main Totals: 52513 bytes | 225 OPs Memory: Tk Totals: 154632 bytes | 1663 OPs Memory: Tk::Adjuster Totals: 99843 bytes | 2000 OPs Memory: Tk::Balloon Totals: 212545 bytes | 2939 OPs Memory: Tk::BrowseEntry Totals: 126060 bytes | 2519 OPs Memory: Tk::Canvas Totals: 22194 bytes | 244 OPs Memory: Tk::CursorControl Totals: 161874 bytes | 2843 OPs Memory: Tk::Entry Totals: 122144 bytes | 2324 OPs Memory: Tk::ItemStyle Totals: 6995 bytes | 91 OPs Memory: Tk::JPEG Totals: 1911 bytes | 1 OPs Memory: Tk::Label Totals: 1824 bytes | 11 OPs Memory: Tk::LabEntry Totals: 4822 bytes | 77 OPs Memory: Tk::MListbox Totals: 214159 bytes | 3940 OPs Memory: Tk::Menu Totals: 193278 bytes | 4004 OPs Memory: Tk::Pixmap Totals: 2601 bytes | 6 OPs Memory: Tk::ROText Totals: 8104 bytes | 127 OPs Memory: Tk::Scrollbar Totals: 31046 bytes | 472 OPs Grand Total: 1416545
    And running the above and using taskman (win32) to view the footprint, it give ~8megs (base perl takes an extra 1.7m)...(unless my poor math skills have affected my thinking ;-)