No coverage for runtime with Devel::Cover and ModPerl::Registry
Asked Answered
K

2

3

When I'm running Devel::Cover with ModPerl::Registry, I get no coverage info except for BEGIN blocks. When I'm running the same script with Devel::Cover from command line or as a CGI, everything works alright (obviously).

How can I make Devel::Cover "see" my code being executed in the runtime?

Here's Devel::Cover related stuff in my httpd.conf:

MaxClients 1
PerlSetEnv DEVEL_COVER_OPTIONS -db,/tmp/cover_db,-silent,1
PerlRequire /var/www/project/startup.pl

Here's startup.pl:

#!/usr/bin/perl
use strict;
use warnings;

use Apache2::Directive ();

BEGIN {
    # Devel::Cover database must be writable by worker processes
    my $conftree = Apache2::Directive::conftree->as_hash;
    my $name = $conftree->{User}
        or die "couldn't find user in Apache config";
    print "user=$name\n";

    my $uid = getpwnam($name);
    defined $uid
        or die "couldn't determine uid by name";

    no warnings 'redefine';
    local $> = $uid;

    require Devel::Cover;

    my $old_report = \&Devel::Cover::report;
    *Devel::Cover::report = sub { local $> = $uid; $old_report->(@_) };

    Devel::Cover->import;
}

1;

(As you may see, I made a monkey patch for Devel::Cover since startup.pl is being run by root, but worker processes run under a different user, and otherwise they couldn't read directories created by startup.pl. If you know a better solution, make a note, please.)

Kurtis answered 8/4, 2010 at 9:32 Comment(0)
G
1

Try running apache with the -X switch, to make it run as a single process. You may also want to set MaxRequestsPerChild to a low value (maybe even 1) so that it will exit after a small number of requests.

Gauss answered 10/2, 2011 at 21:25 Comment(1)
-X maybe, but wouldn't limiting MaxRequestsPerChild actually make your coverage data end sooner than you would want?Scoot
A
1

I think is due to Devel::Cover coming in too late to add hooks, i.e. after all your code has been compiled. I'd try adding use Devel::Cover at the beginning of your startup.pl, or PerlModule Devel::Cover before the other mod_perl stuff in httpd.conf.

Alleviate answered 6/9, 2014 at 16:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.