Getting NYTProf to work with vhosts that use PerlOptions +Parent

Getting NYTProf to work with vhosts that use PerlOptions +Parent

am 28.04.2010 19:48:55 von Tim Bunce

This is proving to be tricky.

If I load Devel::NYTProf::Apache[1] in the main part of httpd.conf then
I get a profile that includes all the activity *except* for any activity
in vhosts that use +Parent.

If I load it inside the VirtualHost section then I get a profile of
activity within that vhost. Great. Except there's a problem...

For a profile to be useful it must be terminated properly. Devel::NYTProf
does that using an END block. Devel::NYTProf::Apache does that using

sub child_exit { DB::_finish() }

my $s = Apache2::ServerUtil->server;
$s->push_handlers(PerlChildExitHandler => \&child_exit);

That works fine normally, but doesn't work with PerlOptions +Parent.
I get an error:
[error] lookup of 'Devel::NYTProf::Apache::child_exit' failed

I presume that's because the $s doesn't refer to the vhost "I'm in".
I can use $s->next (after require Apache2::ServerRec) to iterate over
the vhosts but I can't see a way to find "my" vhost.

Is there one?

What I'm looking for is some way for *a specific vhost perl interpreter*
to run code at PerlChildExitHandler *in that interpreter*.

Any ideas?

Tim.

p.s. Simply adding END { DB::_finish() } to Devel::NYTProf::Apache gives
me a profile that ends during server initialization because the vhost
perl interpreter is initialized using perl_run() and PL_exit_flags |=
PERL_EXIT_DESTRUCT_END has not been set. So I've now set PL_exit_flags
via NYTProf and that's giving me a usable profile for my limited case.
I've not yet looked-into how to generalise that into code that's work in
normal (non +Parent) case.

[1] http://cpansearch.perl.org/src/TIMB/Devel-NYTProf-3.11/lib/D evel/NYTProf/Apache.pm

Re: Getting NYTProf to work with vhosts that use PerlOptions +Parent

am 29.04.2010 05:25:14 von Adam Prime

Maybe you could try doing the push_handler for the ChildExitHandler when
the ChildInitHandler executes? Just a shot in the dark.

Adam

Tim Bunce wrote:
> This is proving to be tricky.
>
> If I load Devel::NYTProf::Apache[1] in the main part of httpd.conf then
> I get a profile that includes all the activity *except* for any activity
> in vhosts that use +Parent.
>
> If I load it inside the VirtualHost section then I get a profile of
> activity within that vhost. Great. Except there's a problem...
>
> For a profile to be useful it must be terminated properly. Devel::NYTProf
> does that using an END block. Devel::NYTProf::Apache does that using
>
> sub child_exit { DB::_finish() }
>
> my $s = Apache2::ServerUtil->server;
> $s->push_handlers(PerlChildExitHandler => \&child_exit);
>
> That works fine normally, but doesn't work with PerlOptions +Parent.
> I get an error:
> [error] lookup of 'Devel::NYTProf::Apache::child_exit' failed
>
> I presume that's because the $s doesn't refer to the vhost "I'm in".
> I can use $s->next (after require Apache2::ServerRec) to iterate over
> the vhosts but I can't see a way to find "my" vhost.
>
> Is there one?
>
> What I'm looking for is some way for *a specific vhost perl interpreter*
> to run code at PerlChildExitHandler *in that interpreter*.
>
> Any ideas?
>
> Tim.
>
> p.s. Simply adding END { DB::_finish() } to Devel::NYTProf::Apache gives
> me a profile that ends during server initialization because the vhost
> perl interpreter is initialized using perl_run() and PL_exit_flags |=
> PERL_EXIT_DESTRUCT_END has not been set. So I've now set PL_exit_flags
> via NYTProf and that's giving me a usable profile for my limited case.
> I've not yet looked-into how to generalise that into code that's work in
> normal (non +Parent) case.
>
> [1] http://cpansearch.perl.org/src/TIMB/Devel-NYTProf-3.11/lib/D evel/NYTProf/Apache.pm

Re: Getting NYTProf to work with vhosts that use PerlOptions +Parent

am 29.04.2010 13:39:07 von Tim Bunce

On Wed, Apr 28, 2010 at 11:25:14PM -0400, Adam Prime wrote:
> Maybe you could try doing the push_handler for the ChildExitHandler
> when the ChildInitHandler executes? Just a shot in the dark.

Umm, but how to I get the ChildInitHandler handle to use the right perl
interpreter?

Tim.

> Adam
>
> Tim Bunce wrote:
> >This is proving to be tricky.
> >
> >If I load Devel::NYTProf::Apache[1] in the main part of httpd.conf then
> >I get a profile that includes all the activity *except* for any activity
> >in vhosts that use +Parent.
> >
> >If I load it inside the VirtualHost section then I get a profile of
> >activity within that vhost. Great. Except there's a problem...
> >
> >For a profile to be useful it must be terminated properly. Devel::NYTProf
> >does that using an END block. Devel::NYTProf::Apache does that using
> >
> > sub child_exit { DB::_finish() }
> >
> > my $s = Apache2::ServerUtil->server;
> > $s->push_handlers(PerlChildExitHandler => \&child_exit);
> >
> >That works fine normally, but doesn't work with PerlOptions +Parent.
> >I get an error:
> > [error] lookup of 'Devel::NYTProf::Apache::child_exit' failed
> >
> >I presume that's because the $s doesn't refer to the vhost "I'm in".
> >I can use $s->next (after require Apache2::ServerRec) to iterate over
> >the vhosts but I can't see a way to find "my" vhost.
> >
> >Is there one?
> >
> >What I'm looking for is some way for *a specific vhost perl interpreter*
> >to run code at PerlChildExitHandler *in that interpreter*.
> >
> >Any ideas?
> >
> >Tim.
> >
> >p.s. Simply adding END { DB::_finish() } to Devel::NYTProf::Apache gives
> >me a profile that ends during server initialization because the vhost
> >perl interpreter is initialized using perl_run() and PL_exit_flags |=
> >PERL_EXIT_DESTRUCT_END has not been set. So I've now set PL_exit_flags
> >via NYTProf and that's giving me a usable profile for my limited case.
> >I've not yet looked-into how to generalise that into code that's work in
> >normal (non +Parent) case.
> >
> >[1] http://cpansearch.perl.org/src/TIMB/Devel-NYTProf-3.11/lib/D evel/NYTProf/Apache.pm
>
>

Re: Getting NYTProf to work with vhosts that use PerlOptions +Parent

am 30.04.2010 01:02:05 von Fred Moyer

On Thu, Apr 29, 2010 at 4:39 AM, Tim Bunce wrote:
> On Wed, Apr 28, 2010 at 11:25:14PM -0400, Adam Prime wrote:
>> Maybe you could try doing the push_handler for the ChildExitHandler
>> when the ChildInitHandler executes? =A0Just a shot in the dark.
>
> Umm, but how to I get the ChildInitHandler handle to use the right perl
> interpreter?

I just tried to setup a test case but I don't have perl configured
with ithreads.

Can you do something like this, since each vhost servername is tied to
that perl intepreter? (warning, untested code)

sub child_exit {
my $vhost_servername =3D shift;

my $s =3D Apache2::ServerUtil->server;
return unless $s->hostname eq $vhost_servername;

DB::_finish();
}

$s->push_handlers(PerlChildExitHandler =3D> \&child_exit($s->server_hostnam=
e );


>
> Tim.
>
>> Adam
>>
>> Tim Bunce wrote:
>> >This is proving to be tricky.
>> >
>> >If I load Devel::NYTProf::Apache[1] in the main part of httpd.conf then
>> >I get a profile that includes all the activity *except* for any activit=
y
>> >in vhosts that use +Parent.
>> >
>> >If I load it inside the VirtualHost section then I get a profile of
>> >activity within that vhost. Great. Except there's a problem...
>> >
>> >For a profile to be useful it must be terminated properly. Devel::NYTPr=
of
>> >does that using an END block. Devel::NYTProf::Apache does that using
>> >
>> > =A0 =A0sub child_exit { DB::_finish() }
>> >
>> > =A0 =A0my $s =3D Apache2::ServerUtil->server;
>> > =A0 =A0$s->push_handlers(PerlChildExitHandler =3D> \&child_exit);
>> >
>> >That works fine normally, but doesn't work with PerlOptions +Parent.
>> >I get an error:
>> > =A0 =A0[error] lookup of 'Devel::NYTProf::Apache::child_exit' failed
>> >
>> >I presume that's because the $s doesn't refer to the vhost "I'm in".
>> >I can use $s->next (after require Apache2::ServerRec) to iterate over
>> >the vhosts but I can't see a way to find "my" vhost.
>> >
>> >Is there one?
>> >
>> >What I'm looking for is some way for *a specific vhost perl interpreter=
*
>> >to run code at PerlChildExitHandler *in that interpreter*.
>> >
>> >Any ideas?
>> >
>> >Tim.
>> >
>> >p.s. Simply adding END { DB::_finish() } to Devel::NYTProf::Apache give=
s
>> >me a profile that ends during server initialization because the vhost
>> >perl interpreter is initialized using perl_run() and PL_exit_flags |=3D
>> >PERL_EXIT_DESTRUCT_END has not been set. =A0So I've now set PL_exit_fla=
gs
>> >via NYTProf and that's giving me a usable profile for my limited case.
>> >I've not yet looked-into how to generalise that into code that's work i=
n
>> >normal (non +Parent) case.
>> >
>> >[1] http://cpansearch.perl.org/src/TIMB/Devel-NYTProf-3.11/lib/D evel/NY=
TProf/Apache.pm
>>
>>
>

Re: Getting NYTProf to work with vhosts that use PerlOptions +Parent

am 30.04.2010 13:32:32 von Tim Bunce

On Thu, Apr 29, 2010 at 04:02:05PM -0700, Fred Moyer wrote:
> On Thu, Apr 29, 2010 at 4:39 AM, Tim Bunce wrote:
> > On Wed, Apr 28, 2010 at 11:25:14PM -0400, Adam Prime wrote:
> >> Maybe you could try doing the push_handler for the ChildExitHandler
> >> when the ChildInitHandler executes? =A0Just a shot in the dark.
> >
> > Umm, but how to I get the ChildInitHandler handle to use the right pe=
rl
> > interpreter?
>=20
> I just tried to setup a test case but I don't have perl configured
> with ithreads.
>=20
> Can you do something like this, since each vhost servername is tied to
> that perl intepreter? (warning, untested code)
>=20
> sub child_exit {
> my $vhost_servername =3D shift;
>=20
> my $s =3D Apache2::ServerUtil->server;
> return unless $s->hostname eq $vhost_servername;
>=20
> DB::_finish();
> }
>=20
> $s->push_handlers(PerlChildExitHandler =3D> \&child_exit($s->server_hos=
tname );

The \&child_exit($s->server_hostname) syntax wouldn't work but I'll try
something along those lines. Thanks.

Tim.