【问题标题】:No coverage for runtime with Devel::Cover and ModPerl::Registry使用 Devel::Cover 和 ModPerl::Registry 不覆盖运行时
【发布时间】:2011-02-05 15:03:26
【问题描述】:

当我使用ModPerl::Registry 运行Devel::Cover 时,除了BEGIN 块之外,我没有得到任何覆盖信息。当我从命令行或作为 CGI 使用 Devel::Cover 运行相同的脚本时,一切正常(显然)。

如何让Devel::Cover“看到”我的代码在运行时执行?

这是我的httpd.conf 中的Devel::Cover 相关内容:

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

这里是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;

(如您所见,我为Devel::Cover 制作了一个猴子补丁,因为startup.pl 正在由root 运行,但是工作进程在不同的用户下运行,否则它们无法读取由@ 创建的目录987654334@。如果您知道更好的解决方案,请记下。)

【问题讨论】:

    标签: perl code-coverage mod-perl2 devel-cover mod-perl-registry


    【解决方案1】:

    尝试使用-X 开关运行apache,使其作为单个进程运行。您可能还希望将MaxRequestsPerChild 设置为较低的值(甚至可能为1),以便在少量请求后退出。

    【讨论】:

    • -X 可能,但不会限制MaxRequestsPerChild 实际上会使您的覆盖率数据比您想要的更快结束吗?
    【解决方案2】:

    我认为是由于 Devel::Cover 来得太晚而无法添加钩子,即在您的所有代码都已编译之后。我会尝试在您的 startup.pl 开头添加use Devel::Cover,或者在 httpd.conf 中的其他 mod_perl 内容之前添加PerlModule Devel::Cover

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-08
      • 1970-01-01
      • 2011-01-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多