blib/script/nytprofcsv

filter: Statementstmt 73.7% 45 / 61 Branchbran 45.8% 11 / 24 Conditioncond 100% 6 / 6 MC/DCmcdc 100% 3 / 3 Subroutinesub 81.8% 9 / 11 Podpod n/a totaltotal 70.4% 74 / 105 CC 8 SCAR 13.2
CC
8
Cov
68%
_delete
6.8
__ANON__
6.1
usage
2.0
CRAP 3.7
« blib/script/nytprofcalls ↑ Summary t/test06.p »
1 #!/usr/local/bin/perl
2 ##########################################################
3 # This script is part of the Devel::NYTProf distribution
4 #
5 # Copyright, contact and other information can be found
6 # at the bottom of this file, or by going to:
7 # http://metacpan.org/release/Devel-NYTProf/
8 #
9 ##########################################################
10  
11 304 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 304 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 304 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 304 ▶use Getopt::Long;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 304 ▶use Devel::NYTProf::Reader;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 304 our $VERSION = '6.16';
20  
21 304 ▶use constant NUMERIC_PRECISION => 5;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 304 my %delimiters = (
24 comma => ",",
25 tab => "\t",
26 );
27  
28 304 my %opt = (
29 file => 'nytprof.out',
30 out => 'nytprof',
31 delim => 'comma',
32 );
33 GetOptions(\%opt, qw/file|f=s delete|d out|o=s help|h delim=s annotated|a/)
34 304 ▶ or do {
Branch: 1 branch
BranchTrueFalseTotal
&GetOptions(\%opt, ("file|f=s", "delete|d", "out|o=s", "help|h", "delim=s", "annotated|a")) or do { usage(); exit 1 } 304 0 304
35 0 usage();
36 0 exit 1;
37 };
38  
39 304 ▶if (defined($opt{help})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt{"help"}) 0 304 304
40 0 usage();
41 0 exit;
42 }
43  
44 304 ▶$opt{delim} = $delimiters{ $opt{delim} } if exists $delimiters{ $opt{delim} };
Branch: 1 branch
BranchTrueFalseTotal
if exists $delimiters{$opt{"delim"}} 304 0 304
45  
46 # handle file selection option
47 304 ▶if (!-r $opt{file}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-r $opt{"file"}) 0 304 304
48 0 die "$0: Unable to access $opt{file}\n";
49 }
50  
51 # handle output location
52 304 ▶if (!-e $opt{out}) {
Branch: 3 branches
BranchTrueFalseTotal
if (not -e $opt{'out'}) { } 0 304 304
elsif (not -d $opt{'out'}) { } 0 304 304
elsif (not -w $opt{'out'}) { } 0 304 304
53  
54 # will be created
55 }
56 elsif (!-d $opt{out}) {
57 0 die "$0: Specified output directory `$opt{out}' is a file. whoops!\n";
58 }
59 elsif (!-w $opt{out}) {
60 0 die "$0: Unable to write to output directory `$opt{out}'\n";
61 }
62  
63 # handle deleting old db's
64 304 ▶if (defined($opt{'delete'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt{"delete"}) 0 304 304
65 0 _delete();
66 }
67  
68 304 print "Generating CSV report...\n";
69 304 my $reporter = new Devel::NYTProf::Reader($opt{file});
70  
71 # place to store this
72 304 $reporter->output_dir($opt{out});
73  
74 10302392 ▶$reporter->set_param(mk_report_source_line => sub {
Subroutine __ANON__: called CC=6 SCAR=18.1
75 10302392 my ($linenum, $line, $stats_for_line, $statistics, $profile, $filestr) = @_;
76 10302392 $line =~ s/^\s*//; # trim leading spaces
77 10302392 my $delim = $opt{delim};
78  
79 10302392 ▶ my $time = $stats_for_line->{'time'} || 0;
Condition100%2/2
$stats_for_line->{'time'} || 0
l!l
3201639982229
MC/DC100%1/1
$stats_for_line->{'time'} || 0
$stats_for_line->{'time'}
Truth table100%2/2
A
A= $stats_for_line->{'time'}
Aresult
11
00
80 10302392 ▶ my $calls = $stats_for_line->{'calls'} || 0;
Condition100%2/2
$stats_for_line->{'calls'} || 0
l!l
3201669982226
MC/DC100%1/1
$stats_for_line->{'calls'} || 0
$stats_for_line->{'calls'}
Truth table100%2/2
A
A= $stats_for_line->{'calls'}
Aresult
11
00
81 10302392 ▶ $time += $stats_for_line->{evalcall_stmts_time_nested} || 0;
Condition100%2/2
$stats_for_line->{'evalcall_stmts_time_nested'} || 0
l!l
184810300544
MC/DC100%1/1
$stats_for_line->{'evalcall_stmts_time_nested'} || 0
$stats_for_line->{'evalcall_stmts_time_nested'}
Truth table100%2/2
A
A= $stats_for_line->{'evalcall_stmts_time_nested'}
Aresult
11
00
82 #$calls ||= 1 if exists $stats_for_line->{evalcall_stmts_time_nested};
83  
84 10302392 ▶ my $text = sprintf("%f%s%g%s%f%s%s\n",
Branch: 1 branch
BranchTrueFalseTotal
$calls ? : 320166 9982226 10302392
85 $time, $delim,
86 $calls, $delim,
87 ($calls) ? $time/$calls : 0, $delim,
88 $line,
89 );
90 10302392 ▶ return $text unless $opt{annotated};
Branch: 1 branch
BranchTrueFalseTotal
unless $opt{"annotated"} 10302392 0 10302392
91  
92 # srcline
93 0 $text = "srcline$delim$text";
94  
95 0 return $text;
96 304 });
97  
98 304 ▶$reporter->set_param(mk_report_xsub_line => sub { "" });
Subroutine __ANON__: called CC=1 SCAR=0.0
99  
100 # generate the files
101 304 $reporter->report();
102  
103 # Delete the previous database if it exists
104 0 ▶sub _delete {
Subroutine _delete: not called CC=3 SCAR=19.2
105 0 ▶ if (-d $opt{out}) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $opt{"out"}) 0 0 0
106 0 print "Deleting $opt{out}\n";
107 0 ▶ unlink glob($opt{out} . "/*");
Subroutine BEGIN: called CC=1 SCAR=0.2
108 0 unlink glob($opt{out} . "/.*");
109 0 ▶ rmdir $opt{out} or confess "Delete of $opt{out} failed: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
rmdir $opt{"out"} or confess(qq[Delete of $opt{"out"} failed: $!\n]) 0 0 0
110 }
111 }
112  
113 0 ▶sub usage {
Subroutine usage: not called CC=1 SCAR=6.9
114 0 print <<END
115 usage: [perl] nytprofcsv [opts]
116 --file <file>, -f <file> Use the specified file as Devel::NYTProf database
117 file. [default: ./nytprof.out]
118 --out <dir>, -o <dir> Place generated files here [default: ./nytprof]
119 --delete, -d Delete the old fprofhtml output [uses --out]
120 --help, -h Print this message
121  
122 This script is part of the Devel::NYTProf package
123 See https://metacpan.org/pod/Devel::NYTProf
124 END
125 }
126  
127 __END__
« blib/script/nytprofcalls ↑ Summary t/test06.p »