You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by "Philip M. Gollucci" <pg...@p6m7g8.com> on 2005/08/21 15:22:08 UTC

[PATCH] DBI::ProfileDumper::Apache ported to mp2 RC5+

Hi all,

Nuff said!

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


--- Apache.pm   Tue Dec 14 10:31:39 2004
+++ Apache.pm.new       Sun Aug 21 08:18:22 2005
@@ -108,8 +108,10 @@
  use vars qw($VERSION @ISA);
  $VERSION = "1.0";
  @ISA = qw(DBI::ProfileDumper);
+
+use constant 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 +122,16 @@
      my $self = shift;

      # setup File per process
-    my $path = Apache->server_root_relative("logs/");
+    my $path;
+    if (MP2) {
+        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.$$");


-- 
END
------------------------------------------------------------
     What doesn't kill us can only make us stronger.
                 Nothing is impossible.
				
Philip M. Gollucci (pgollucci@p6m7g8.com) 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


Re: [PATCH] DBI::ProfileDumper::Apache ported to mp2 RC5+

Posted by "Philip M. Gollucci" <pg...@p6m7g8.com>.
Sam Tregar wrote:
> Cool, thanks.  One question (which you may perfectly reasonably ask me
> to check for myself): won't this cause a warning when
> MOD_PERL_API_VERSION is undefined?
> 
>    $MP2 = $ENV{MOD_PERL_API_VERSION} == 2 ? 1 : 0;
> 
> Perhaps this would be better:
> 
>    $MP2 = (($ENV{MOD_PERL_API_VERSION} || 0) == 2);
> 
> -sam
Yes,

I think we usually do:

$MP2 = (exists $ENV{MOD_PERL_API_VERSION} &&
     $ENV{MOD_PERL_API_VERSION} == 2) ? 1 : 0;

but either will work.

good catch.

-- 
END
------------------------------------------------------------
     What doesn't kill us can only make us stronger.
                 Nothing is impossible.
				
Philip M. Gollucci (pgollucci@p6m7g8.com) 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


Re: [PATCH] DBI::ProfileDumper::Apache ported to mp2 RC5+

Posted by Sam Tregar <sa...@tregar.com>.
On Sun, 21 Aug 2005, Philip M. Gollucci wrote:

> 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.

Cool, thanks.  One question (which you may perfectly reasonably ask me
to check for myself): won't this cause a warning when
MOD_PERL_API_VERSION is undefined?

   $MP2 = $ENV{MOD_PERL_API_VERSION} == 2 ? 1 : 0;

Perhaps this would be better:

   $MP2 = (($ENV{MOD_PERL_API_VERSION} || 0) == 2);

-sam

Re: [PATCH] DBI::ProfileDumper::Apache ported to mp2 RC5+

Posted by Tim Bunce <Ti...@pobox.com>.
[I wrote this over a week ago but queued it waiting till I submitted
the changes. That's still not happened yet so I'll just post it anyway.]

On Sun, Aug 21, 2005 at 05:22:34PM -0400, Philip M. Gollucci wrote:
> 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.

For some reason I got rejects so had to apply the patch by hand.

In the process I opted to use constant again. It's already loaded by
DBI::Profile and the perl compiler can use constants to completely
eliminate code for statements like if(){} blocks it knows won't be entered.

I also tweaked the $ENV{MOD_PERL_API_VERSION} test to avoid undef warnings.

Thanks.

Tim.

> 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 (pgollucci@p6m7g8.com) 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
> 

Re: [PATCH] DBI::ProfileDumper::Apache ported to mp2 RC5+

Posted by "Philip M. Gollucci" <pg...@p6m7g8.com>.
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 (pgollucci@p6m7g8.com) 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


Re: [PATCH] DBI::ProfileDumper::Apache ported to mp2 RC5+

Posted by Tim Bunce <Ti...@pobox.com>.
On Sun, Aug 21, 2005 at 01:59:34PM -0400, Sam Tregar wrote:
> On Sun, 21 Aug 2005, Philip M. Gollucci wrote:
> 
> > Hi all,
> > 
> > Nuff said!
> 
> 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().
> 
> > P.S.
> >   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.

Thanks Philip!

Tim.

Re: [PATCH] DBI::ProfileDumper::Apache ported to mp2 RC5+

Posted by Sam Tregar <sa...@tregar.com>.
On Sun, 21 Aug 2005, Philip M. Gollucci wrote:

> Hi all,
> 
> Nuff said!

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().

> P.S.
>   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?  I'd check it
out myself but I don't have an Apache2/mod_perl setup at the moment.

-sam