| 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
| |||||||||||||||||||
| 35 | 0 | usage(); | |||||||||||||||||
| 36 | 0 | exit 1; | |||||||||||||||||
| 37 | }; | ||||||||||||||||||
| 38 | |||||||||||||||||||
| 39 | 304 | ▶ | if (defined($opt{help})) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 40 | 0 | usage(); | |||||||||||||||||
| 41 | 0 | exit; | |||||||||||||||||
| 42 | } | ||||||||||||||||||
| 43 | |||||||||||||||||||
| 44 | 304 | ▶ | $opt{delim} = $delimiters{ $opt{delim} } if exists $delimiters{ $opt{delim} }; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 45 | |||||||||||||||||||
| 46 | # handle file selection option | ||||||||||||||||||
| 47 | 304 | ▶ | if (!-r $opt{file}) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 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
| |||||||||||||||||||
| 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
| |||||||||||||||||||
| 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
MC/DC100%1/1
$stats_for_line->{'time'} || 0
$stats_for_line->{'time'}
Truth table100%2/2
A
A= $stats_for_line->{'time'}
| |||||||||||||||||||
| 80 | 10302392 | ▶ | my $calls = $stats_for_line->{'calls'} || 0; | ||||||||||||||||
|
Condition100%2/2
$stats_for_line->{'calls'} || 0
MC/DC100%1/1
$stats_for_line->{'calls'} || 0
$stats_for_line->{'calls'}
Truth table100%2/2
A
A= $stats_for_line->{'calls'}
| |||||||||||||||||||
| 81 | 10302392 | ▶ | $time += $stats_for_line->{evalcall_stmts_time_nested} || 0; | ||||||||||||||||
|
Condition100%2/2
$stats_for_line->{'evalcall_stmts_time_nested'} || 0
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'}
| |||||||||||||||||||
| 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
| |||||||||||||||||||
| 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
| |||||||||||||||||||
| 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
| |||||||||||||||||||
| 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
| |||||||||||||||||||
| 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__ | ||||||||||||||||||