Someone has asked how to check the compiled size of subs and vars in
mod_perl. New Apache::Status does it for you. There are many new features
in the new Apache::Status, this post covers only the 'Memory Usage'
feature.

Apparently it's a very easy task.

Installation:

* grab the latest CVS snaphost of mod_perl (you need the latest
Apache::Status module) perl.apache.org/from-cvs/modperl

* build mod_perl

* install B::TerseSize

Configuration:

* Configure /perl-status if you didn't before, e.g:

<Location /perl-status>
  SetHandler perl-script
  PerlHandler Apache::Status
  order deny,allow
  #deny from all
  #allow from ...
</Location>

* Add to httpd.conf

PerlSetVar StatusOptionsAll On
PerlSetVar StatusTerse On
PerlSetVar StatusTerseSize On
PerlSetVar StatusTerseSizeMainSummary On

* start the server (best in httpd -X mode)

Usage: 

>From your favorite Netscape browser

* fetch http://localhost/perl-status

* clock on 'Loaded Modules' or 'Compiled Registry Scripts'

* click on module or script of your choice (you might need to run some
script/handler before you will see it here unless it was preloaded)

* click on 'Memory Usage' at the bottom

* Now you will see all the variables and subs and their sizes.  Note (you
might have to reload it a few times, at least it failed for me every 2nd
reload).

Now you can start to optimize your code, or choose one of the 2 versions.
To show you how you can help yourself let's prepare 2 script one 

For example let's compare OO vs methods CGI.pm's interfaces:

As you will see below the first OO script uses about 2k bytes while the
second script (methods interface) uses about 18k. I'm not trying to prove
a thing, just bringing an example so please no protest is required :)

Here are the code and the numbers:

Code:
1) 
use CGI ();
my $q = new CGI;
print $q->header;
print $q->b("Hello");

2)
use CGI qw(:standard);
print header();
print b("Hello");


Sizes:
1)
Totals: 1966 bytes | 27 OPs

handler 1514 bytes | 27 OPs
exit     116 bytes |  0 OPs

2)
Totals: 17969 bytes | 19 OPs

handler              1117 bytes | 19 OPs
start_multipart_form  132 bytes |  0 OPs
use_named_parameters  132 bytes |  0 OPs
end_multipart_form    130 bytes |  0 OPs
restore_parameters    130 bytes |  0 OPs
server_software       127 bytes |  0 OPs
server_protocol       127 bytes |  0 OPs
path_translated       127 bytes |  0 OPs
save_parameters       127 bytes |  0 OPs
scrolling_list        126 bytes |  0 OPs
request_method        126 bytes |  0 OPs
password_field        126 bytes |  0 OPs
checkbox_group        126 bytes |  0 OPs
query_string          124 bytes |  0 OPs
import_names          124 bytes |  0 OPs
virtual_host          124 bytes |  0 OPs
remote_ident          124 bytes |  0 OPs
content_type          124 bytes |  0 OPs
image_button          124 bytes |  0 OPs
remote_addr           123 bytes |  0 OPs
remote_host           123 bytes |  0 OPs
URL_ENCODED           123 bytes |  0 OPs
tmpFileName           123 bytes |  0 OPs
server_port           123 bytes |  0 OPs
param_fetch           123 bytes |  0 OPs
radio_group           123 bytes |  0 OPs
server_name           123 bytes |  0 OPs
script_name           123 bytes |  0 OPs
remote_user           123 bytes |  0 OPs
uploadInfo            122 bytes |  0 OPs
start_html            122 bytes |  0 OPs
autoEscape            122 bytes |  0 OPs
start_form            122 bytes |  0 OPs
user_agent            122 bytes |  0 OPs
raw_cookie            122 bytes |  0 OPs
Delete_all            122 bytes |  0 OPs
blockquote            122 bytes |  0 OPs
popup_menu            122 bytes |  0 OPs
url_param             121 bytes |  0 OPs
user_name             121 bytes |  0 OPs
MULTIPART             121 bytes |  0 OPs
startform             121 bytes |  0 OPs
cgi_error             121 bytes |  0 OPs
auth_type             121 bytes |  0 OPs
path_info             121 bytes |  0 OPs
filefield             121 bytes |  0 OPs
textfield             121 bytes |  0 OPs
textarea              120 bytes |  0 OPs
basefont              120 bytes |  0 OPs
checkbox              120 bytes |  0 OPs
redirect              120 bytes |  0 OPs
defaults              120 bytes |  0 OPs
end_html              120 bytes |  0 OPs
frameset              120 bytes |  0 OPs
end_form              120 bytes |  0 OPs
self_url              120 bytes |  0 OPs
endform               119 bytes |  0 OPs
comment               119 bytes |  0 OPs
referer               119 bytes |  0 OPs
isindex               119 bytes |  0 OPs
caption               119 bytes |  0 OPs
address               119 bytes |  0 OPs
Accept                118 bytes |  0 OPs
upload                118 bytes |  0 OPs
hidden                118 bytes |  0 OPs
strike                118 bytes |  0 OPs
Delete                118 bytes |  0 OPs
submit                118 bytes |  0 OPs
button                118 bytes |  0 OPs
Select                118 bytes |  0 OPs
ilayer                118 bytes |  0 OPs
header                118 bytes |  0 OPs
applet                118 bytes |  0 OPs
nextid                118 bytes |  0 OPs
option                118 bytes |  0 OPs
cookie                118 bytes |  0 OPs
strong                118 bytes |  0 OPs
script                118 bytes |  0 OPs
param                 117 bytes |  0 OPs
frame                 117 bytes |  0 OPs
table                 117 bytes |  0 OPs
layer                 117 bytes |  0 OPs
embed                 117 bytes |  0 OPs
Param                 117 bytes |  0 OPs
style                 117 bytes |  0 OPs
input                 117 bytes |  0 OPs
reset                 117 bytes |  0 OPs
small                 117 bytes |  0 OPs
title                 117 bytes |  0 OPs
samp                  116 bytes |  0 OPs
html                  116 bytes |  0 OPs
meta                  116 bytes |  0 OPs
http                  116 bytes |  0 OPs
Link                  116 bytes |  0 OPs
head                  116 bytes |  0 OPs
cite                  116 bytes |  0 OPs
span                  116 bytes |  0 OPs
font                  116 bytes |  0 OPs
exit                  116 bytes |  0 OPs
body                  116 bytes |  0 OPs
Dump                  116 bytes |  0 OPs
code                  116 bytes |  0 OPs
base                  116 bytes |  0 OPs
menu                  116 bytes |  0 OPs
sup                   115 bytes |  0 OPs
big                   115 bytes |  0 OPs
pre                   115 bytes |  0 OPs
var                   115 bytes |  0 OPs
url                   115 bytes |  0 OPs
img                   115 bytes |  0 OPs
dfn                   115 bytes |  0 OPs
put                   115 bytes |  0 OPs
kbd                   115 bytes |  0 OPs
div                   115 bytes |  0 OPs
Sub                   115 bytes |  0 OPs
Tr                    114 bytes |  0 OPs
hr                    114 bytes |  0 OPs
TR                    114 bytes |  0 OPs
br                    114 bytes |  0 OPs
ul                    114 bytes |  0 OPs
li                    114 bytes |  0 OPs
em                    114 bytes |  0 OPs
dl                    114 bytes |  0 OPs
h1                    114 bytes |  0 OPs
dd                    114 bytes |  0 OPs
h2                    114 bytes |  0 OPs
ol                    114 bytes |  0 OPs
h3                    114 bytes |  0 OPs
tt                    114 bytes |  0 OPs
h4                    114 bytes |  0 OPs
h5                    114 bytes |  0 OPs
h6                    114 bytes |  0 OPs
th                    114 bytes |  0 OPs
td                    114 bytes |  0 OPs
dt                    114 bytes |  0 OPs
u                     113 bytes |  0 OPs
p                     113 bytes |  0 OPs
i                     113 bytes |  0 OPs
b                     113 bytes |  0 OPs
a                     113 bytes |  0 OPs


Enjoy!

_______________________________________________________________________
Stas Bekman    mailto:[EMAIL PROTECTED]      http://www.stason.org/stas
Perl,CGI,Apache,Linux,Web,Java,PC     http://www.stason.org/stas/TULARC
perl.apache.org    modperl.sourcegarden.org   perlmonth.com    perl.org
single o-> + single o-+ = singlesheaven    http://www.singlesheaven.com

Reply via email to