blib/lib/Devel/NYTProf/Run.pm

filter: Statementstmt 86.9% 40 / 46 Branchbran 36.3% 8 / 22 Conditioncond 33.3% 4 / 12 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 2 totaltotal 62.5% 60 / 96 CC 15 SCAR 26.1
CC
15
Cov
65%
profile_this
22.9
perl_command_words
8.1
BEGIN
1.0
CRAP 13.6
« blib/lib/Devel/NYTProf/Constants.pm ↑ Summary blib/lib/Devel/NYTProf/Data.pm »
1 package Devel::NYTProf::Run;
2  
3 # vim: ts=8 sw=4 expandtab:
4 ##########################################################
5 # This script is part of the Devel::NYTProf distribution
6 #
7 # Copyright, contact and other information can be found
8 # at the bottom of this file, or by going to:
9 # http://metacpan.org/release/Devel-NYTProf/
10 #
11 ###########################################################
12  
13 =head1 NAME
14  
15 Devel::NYTProf::Run - Invoke NYTProf on a piece of code and return the profile
16  
17 =head1 DESCRIPTION
18  
19 This module is experimental and subject to change.
20  
21 =cut
22  
23 44 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 44 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 44 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 44 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 44 ▶use Config qw(%Config);
Subroutine BEGIN: called CC=1 SCAR=0.0
30 44 ▶use Devel::NYTProf::Data;
Subroutine BEGIN: called CC=1 SCAR=0.0
31  
32 44 our @EXPORT_OK = qw(
33 profile_this
34 perl_command_words
35 );
36  
37  
38 44 my $this_perl = $^X;
39 44 ▶$this_perl .= $Config{_exe} if $^O ne 'VMS' and $this_perl !~ m/$Config{_exe}$/i;
Branch: 1 branch
BranchTrueFalseTotal
if $^O ne "VMS" and not $this_perl =~ /$Devel::NYTProf::Run::Config{"_exe"}$/i 0 44 44
Condition33%1/3
$^O ne "VMS" and not $this_perl =~ /$Devel::NYTProf::Run::Config{"_exe"}$/i
!ll&&!rl&&r
0440
MC/DC0%0/2
$^O ne "VMS" and not $this_perl =~ /$Devel::NYTProf::Run::Config{"_exe"}$/i
$^O ne "VMS" not $this_perl =~ /$Devel::NYTProf::Run::Config{"_exe"}$/i
Truth table33%1/3
A and not(B)
A= $^O ne "VMS"B= not $this_perl =~ /$Devel::NYTProf::Run::Config{"_exe"}$/i
ABresult
0X0
100
111
40  
41  
42 572 ▶sub perl_command_words {
Subroutine perl_command_words: called CC=5 SCAR=20.9
Pod undocumented
43 572 my %opt = @_;
44  
45 572 my @perl = ($this_perl);
46
47 # testing just $Config{usesitecustomize} isn't reliable for perl 5.11.x
48 572 ▶ if (($Config{usesitecustomize}||'') eq 'define'
Branch: 1 branch
BranchTrueFalseTotal
if (($Devel::NYTProf::Run::Config{"usesitecustomize"} || "") eq "define" or $Devel::NYTProf::Run::Config{"ccflags"} =~ /(?<!\w)-DUSE_SITECUSTOMIZE\b/) 0 572 572
Condition40%2/5
($Devel::NYTProf::Run::Config{"usesitecustomize"} || "") eq "define" or $Devel::NYTProf::Run::Config{"ccflags"} =~ /(?<!\w)-DUSE_SITECUSTOMIZE\b/
l!l&&r!l&&!r
00572
$Devel::NYTProf::Run::Config{'usesitecustomize'} || ''
l!l
0572
MC/DC0%0/2
($Devel::NYTProf::Run::Config{"usesitecustomize"} || "") eq "define" or $Devel::NYTProf::Run::Config{"ccflags"} =~ /(?<!\w)-DUSE_SITECUSTOMIZE\b/
$Devel::NYTProf::Run::Config{'usesitecustomize'} $Devel::NYTProf::Run::Config{"ccflags"} =~ /(?<!\w)-DUSE_SITECUSTOMIZE\b/
Truth table33%1/3
A or B
A= $Devel::NYTProf::Run::Config{'usesitecustomize'}B= $Devel::NYTProf::Run::Config{"ccflags"} =~ /(?<!\w)-DUSE_SITECUSTOMIZE\b/
ABresult
1X1
011
000
49 or $Config{ccflags} =~ /(?<!\w)-DUSE_SITECUSTOMIZE\b/
50 ) {
51 0 ▶ push @perl, '-f' if $opt{skip_sitecustomize};
Branch: 1 branch
BranchTrueFalseTotal
if $opt{"skip_sitecustomize"} 0 0 0
52 }
53  
54 572 return @perl;
55 }
56  
57  
58 # croaks on failure to execute
59 # carps, not croak, if process has non-zero exit status
60 # Devel::NYTProf::Data->new may croak, e.g., if data truncated
61 86 ▶sub profile_this {
Subroutine profile_this: called CC=11 SCAR=31.3
Pod undocumented
62 86 my %opt = @_;
63  
64 86 ▶ my $out_file = $opt{out_file} || 'nytprof.out';
Condition50%1/2
$opt{'out_file'} || 'nytprof.out'
l!l
860
MC/DC0%0/1
$opt{'out_file'} || 'nytprof.out'
$opt{'out_file'}
Truth table50%1/2
A
A= $opt{'out_file'}
Aresult
11
00
65  
66 86 my @perl = (perl_command_words(%opt), '-d:NYTProf');
67  
68 warn sprintf "profile_this() using %s with NYTPROF=%s\n",
69 join(" ", @perl), $ENV{NYTPROF} || ''
70 86 ▶ if $opt{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $opt{"verbose"} 0 86 86
Condition0%0/2
$ENV{'NYTPROF'} || ''
l!l
00
MC/DC0%0/1
$ENV{'NYTPROF'} || ''
$ENV{'NYTPROF'}
Truth table0%0/2
A
A= $ENV{'NYTPROF'}
Aresult
11
00
71  
72 # ensure child has same libs as us (e.g., if we were run with perl -Mblib)
73 86 local $ENV{PERL5LIB} = join($Config{path_sep}, @INC);
74  
75 86 ▶ if (my $src_file = $opt{src_file}) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $src_file = $opt{'src_file'}) { } 0 86 86
elsif (my $src_code = $opt{'src_code'}) { } 86 0 86
76 0 ▶ system(@perl, $src_file) == 0
Branch: 1 branch
BranchTrueFalseTotal
system(@perl, $src_file) == 0 or carp("Exit status $? from @perl $src_file") 0 0 0
77 or carp "Exit status $? from @perl $src_file";
78 }
79 elsif (my $src_code = $opt{src_code}) {
80 86 my $cmd = join ' ', map qq{"$_"}, @perl;
81 86 ▶ open my $fh, "| $cmd"
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "| $cmd" or croak("Can't open pipe to $cmd") 86 0 86
82 or croak "Can't open pipe to $cmd";
83 86 print $fh $src_code;
84 86 ▶ close $fh
Branch: 2 branches
BranchTrueFalseTotal
close $fh or carp($! ? "Error closing $cmd pipe: $!" : "Exit status $? from $cmd") 86 0 86
$! ? : 0 0 0
85 or carp $! ? "Error closing $cmd pipe: $!"
86 : "Exit status $? from $cmd";
87  
88 }
89 else {
90 0 croak "Neither src_file or src_code was provided";
91 }
92  
93 # undocumented hack that's handy for testing
94 86 ▶ if ($opt{htmlopen}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt{"htmlopen"}) 0 86 86
95 0 my @nytprofhtml_open = ("perl", "nytprofhtml", "--open", "-file=$out_file");
96 0 warn "Running @nytprofhtml_open\n";
97 0 system @nytprofhtml_open;
98 }
99  
100 86 my $profile = Devel::NYTProf::Data->new( { filename => $out_file } );
101  
102 86 unlink $out_file;
103  
104 86 return $profile;
105 }
106  
107 44 1;
« blib/lib/Devel/NYTProf/Constants.pm ↑ Summary blib/lib/Devel/NYTProf/Data.pm »