Profiling a CGI Perl script that timeout

I have a Perl CGI application that sometimes does not work, causing it to be killed by Apache and the 504 Gateway Time-out error being sent to the browser. I am trying to profile this application using NYTProf, however I cannot read the profile data:

  $ nytprofhtml -f www/cgi-local/nytprof.out Reading www/cgi-local/nytprof.out Profile data incomplete, inflate error -5 ((null)) at end of input file, perhaps the process didn't exit cleanly or the file has been truncated (refer to TROUBLESHOOTING in the documentation) 

I use the sigexit=1 NYTProf option. Here is a minimal CGI script that reproduces the problem:

 #!/usr/bin/perl -d:NYTProf sleep 1 while 1; 
+6
source share
2 answers

Setting sigexit=1 tells NYTProf to capture the following signals:

 INT HUP PIPE BUS SEGV 

However, when your CGI script expires, Apache sends SIGTERM . You need to catch SIGTERM :

 sigexit=term 

To catch SIGTERM in addition to the default signals, use:

 sigexit=int,hup,pipe,bus,segv,term 
+6
source

CGI.pm has a debugging mode that you can use to run your program from the command line and pass your CGI parameters as a key / value.

It has another function that you can use to save your settings in a file , and then read this file later.

What I did was added code to save the parameters to a file and launch my program through a browser. It also eases my ability to ensure that the browser sends the correct data.

Then I change the code to read the parameters from the file, and run it as often as I need until I have everything else debugged.

Once the program is satisfied from the command line, you can run it through nytprof to find out what happens all the time.

+1
source

All Articles