Hi,

On Sun, Aug 21, 2005 at 01:59:34PM -0400, Sam Tregar wrote:
Very cool!  One comment: don't bother with 'use constant' here.  The
tiny amount of time saved by using a constant will be overwhelmed by
the time used loading constant.pm and calling import().
I wasn't doing it for speed, more of consitency's sake with perl.apache.org docs
and other modules like Apache::DBI, Apache::DB (+friends), and etc.  I have 
however
changed it to a user var ($MP2) per you request.

Tim Bunce wrote:
 I believe its a side effect, but you need to enable
 PerlOptions +GlobalRequest or you get errors in the on_destory() method.

Can you confirm this and add it to the documentation?


(including the error message)

Then send me an updated patch.
I tweaked this to be slightly better. I stole an idea from Apache::DB
Because the Apache::RequestUtil->request() is what needs the
PerlOptions +GlobalRequest, I've added the ability to
PerlSetEnv DBI_PROFILE_APACHE_LOG_DIR /server_root/logs

if you don't want to add +GlobalRequests which will would be useful in
threaded environments as the CLONE() of $r is slow.

I've also added and confirmed this error message to the docs.

Also, I added a Changes entry and generated the diff against SVN.

P.S.
  I upped the version 1.0 to 1.1

Index: lib/DBI/ProfileDumper/Apache.pm
===================================================================
--- lib/DBI/ProfileDumper/Apache.pm     (revision 1470)
+++ lib/DBI/ProfileDumper/Apache.pm     (working copy)
@@ -10,6 +10,22 @@

   PerlSetEnv DBI_PROFILE DBI::ProfileDumper::Apache

+Under mod_perl2 RC5+ you'll need to also add:
+
+  PerlSetEnv DBI_PROFILE_APACHE_LOG_DIR /server_root/logs
+
+  OR add
+
+  PerlOptions +GlobalRequest
+
+to the gobal config section you're about test with
+DBI::ProfileDumper::Apache.  If you don't do this,
+you'll see messages in your error_log similar to:
+
+DBI::ProfileDumper::Apache on_destroy failed: Global $r object is not 
available. Set:
+    PerlOptions +GlobalRequest
+in httpd.conf at ..../DBI/ProfileDumper/Apache.pm line 144
+
 Then restart your server.  Access the code you wish to test using a
 web browser, then shutdown your server.  This will create a set of
 F<dbi.prof.*> files in your Apache log directory.  Get a profiling
@@ -105,11 +121,12 @@

 =cut

-use vars qw($VERSION @ISA);
-$VERSION = "1.0";
+use vars qw($VERSION @ISA $MP2);
+$VERSION = "1.1";
 @ISA = qw(DBI::ProfileDumper);
+$MP2 = $ENV{MOD_PERL_API_VERSION} == 2 ? 1 : 0;
+
 use DBI::ProfileDumper;
-use Apache;
 use File::Spec;

 # Override flush_to_disk() to setup File just in time for output.
@@ -120,7 +137,22 @@
     my $self = shift;

     # setup File per process
-    my $path = Apache->server_root_relative("logs/");
+    my $path;
+
+    if ($MP2) {
+        if ($ENV{DBI_PROFILE_APACHE_LOG_DIR}) {
+            $path = $ENV{DBI_PROFILE_APACHE_LOG_DIR};
+        }
+        else {
+            require Apache2::RequestUtil;
+            require Apache2::ServerUtil;
+            $path = 
Apache2::ServerUtil::server_root_relative(Apache2::RequestUtil->request()->pool, 
"logs/")
+        }
+    }
+    else {
+       require Apache;
+       $path = Apache->server_root_relative("logs/");
+    }
     my $old_file = $self->{File};
     $self->{File} = File::Spec->catfile($path, "$old_file.$$");

Index: Changes
===================================================================
--- Changes     (revision 1470)
+++ Changes     (working copy)
@@ -25,6 +25,9 @@
     $dbh->{Callbacks}->{prepare} = sub { ... };
     With thanks to David Wheeler for the kick start.

+  Ported DBI::ProfileDumper::Apache to mod_perl RC5+
+    thanks to Philip M. Golluci
+
 =head2 Changes in DBI 1.48 (svn rev 928),    14th March 2005

   Fixed DBI::DBD::Metadata generation of type_info_all thanks to Steffen 
Goeldner




--
END
------------------------------------------------------------
    What doesn't kill us can only make us stronger.
                Nothing is impossible.
                                
Philip M. Gollucci ([EMAIL PROTECTED]) 301.254.5198
Consultant / http://p6m7g8.net/Resume/
Senior Developer / Liquidity Services, Inc.
  http://www.liquidityservicesinc.com
       http://www.liquidation.com
       http://www.uksurplus.com
       http://www.govliquidation.com
       http://www.gowholesale.com

Reply via email to