how to profile cgi
Wednesday, January 16th, 2008Here’s an example of a cgi script running so that it is profiled..
script.cgi :
#!/usr/bin/perl -d use Devel::DProf; # do whatever .....
Afterwards, a tmon.out file resides alongside your script.cgi
# dprofpp -I ./tmon.out
Why the heck would you want to profile a cgi??
As I say over and over again to myself and to anyone that may happen to stand around me, I think a cgi is not a program. I think any web application is not supposed to be an application at all.
I think that a web application should be an INTERFACE to a an application.
A cgi may do things like manage authentication, take user input, and give feedback. That’s all. It should NOT do crazy things like perform OCR, make calculations, generate thumbnails, etc etc.
That kind of code should be developed and tested via the command line on a terminal emulator.
After that works, you can make your interface, or WUI, as I like to call them. Web User Interface.
Now, although your web interface may not do much but take input and spit feedback- what is going on behind the scenes may be very complicated.
Sometimes your application runs great, and you get users telling you “hey, it’s slow..”.
You have to perform all the things they do with their variables etc.. to see what’s going on.
Replicating a cgi environment with authentication, encryption, and god knows what else.. is a pain - in fact.. I’ve tried a couple of times and it sucked all my energy out. Screw that.
So this is the next best thing- profile a cgi run!!!
It’s wonderful- if you have a slow cgi app, this is really useful.