| 1 | package Devel::StatProfiler::FlameGraph; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 24 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 24 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 24 | ▶ | use File::ShareDir; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 24 | ▶ | use File::Spec::Functions; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 24 | ▶ | use IPC::Open3 (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 24 | ▶ | use Cwd (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 24 | ▶ | use Symbol (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 24 | my @BASE_CMD = ( | |||||||||||||||||||
| 13 | $^X, | ||||||||||||||||||||
| 14 | File::ShareDir::dist_file('Devel-StatProfiler', 'flamegraph.pl'), | ||||||||||||||||||||
| 15 | '--nametype=sub', | ||||||||||||||||||||
| 16 | '--countname=samples', | ||||||||||||||||||||
| 17 | ); | ||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 0 | ▶ | sub write_attributes { | ||||||||||||||||||
|
Subroutine
write_attributes: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||
| 20 | 0 | my ($class, $file, $attributes, $zoomable) = @_; | |||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | 0 | ▶ | open my $fh, '>', $file or die "Unable to open '$file': $!"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 23 | 0 | for my $sub (keys %$attributes) { | |||||||||||||||||||
| 24 | 0 | my $attrs = $attributes->{$sub}; | |||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | 0 | ▶ | print $fh join( | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 27 | "\t", | ||||||||||||||||||||
| 28 | $sub, | ||||||||||||||||||||
| 29 | map("$_=$attrs->{$_}", | ||||||||||||||||||||
| 30 | $zoomable ? (grep $_ ne 'href', keys %$attrs) : | ||||||||||||||||||||
| 31 | (keys %$attrs)), | ||||||||||||||||||||
| 32 | ), "\n"; | ||||||||||||||||||||
| 33 | } | ||||||||||||||||||||
| 34 | 0 | ▶ | close $fh or die "Unable to close '$file': $!" | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 35 | } | ||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | 0 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 38 | 0 | my ($class, %opts) = @_; | |||||||||||||||||||
| 39 | my $self = bless { | ||||||||||||||||||||
| 40 | directory => $opts{directory}, | ||||||||||||||||||||
| 41 | traces => $opts{traces}, | ||||||||||||||||||||
| 42 | output => $opts{output}, | ||||||||||||||||||||
| 43 | attributes => $opts{attributes}, | ||||||||||||||||||||
| 44 | args => $opts{extra_args}, | ||||||||||||||||||||
| 45 | 0 | stderr => undef, | |||||||||||||||||||
| 46 | }, $class; | ||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | 0 | return $self; | |||||||||||||||||||
| 49 | } | ||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | 0 | ▶ | sub start { | ||||||||||||||||||
|
Subroutine
start: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 52 | 0 | my ($self) = @_; | |||||||||||||||||||
| 53 | 0 | my $cwd = Cwd::cwd; | |||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | 0 | chdir $self->{directory}; | |||||||||||||||||||
| 56 | 0 | (my $stdin, $self->{stderr}) = map Symbol::gensym, 1 .. 2; | |||||||||||||||||||
| 57 | 0 | ▶ | open my $stdout, '>', $self->{output} or die "Error opening '", $self->flamegraph, "': $!"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 58 | 0 | local *FLAMES = $stdout; | |||||||||||||||||||
| 59 | $self->{pid} = IPC::Open3::open3( | ||||||||||||||||||||
| 60 | $stdin, ">&FLAMES", $self->{stderr}, | ||||||||||||||||||||
| 61 | @BASE_CMD, | ||||||||||||||||||||
| 62 | 0 | map("--$_=$self->{args}{$_}", keys %{$self->{args}}), | |||||||||||||||||||
| 63 | "--nameattr=$self->{attributes}", | ||||||||||||||||||||
| 64 | $self->{traces}, | ||||||||||||||||||||
| 65 | 0 | ); | |||||||||||||||||||
| 66 | 0 | chdir $cwd; | |||||||||||||||||||
| 67 | } | ||||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | 0 | ▶ | sub wait { | ||||||||||||||||||
|
Subroutine
wait: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||
| 70 | 0 | my ($self) = @_; | |||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | 0 | ▶ | if (waitpid($self->{pid}, 0) != $self->{pid}) { | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 73 | 0 | die "Generating ", $self->flamegraph, " failed:\n", $self->_errors; | |||||||||||||||||||
| 74 | } elsif ($? != 0) { | ||||||||||||||||||||
| 75 | 0 | die "Generating ", $self->flamegraph, " failed\n", $self->_errors;; | |||||||||||||||||||
| 76 | } | ||||||||||||||||||||
| 77 | } | ||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | 0 | ▶ | sub flamegraph { | ||||||||||||||||||
|
Subroutine
flamegraph: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 80 | 0 | my ($self) = @_; | |||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | 0 | return File::Spec::Functions::catfile($self->{directory}, $self->{output}); | |||||||||||||||||||
| 83 | } | ||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | 0 | ▶ | sub flamegraph_base { | ||||||||||||||||||
|
Subroutine
flamegraph_base: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 86 | 0 | my ($self) = @_; | |||||||||||||||||||
| 87 | |||||||||||||||||||||
| 88 | 0 | return $self->{output}; | |||||||||||||||||||
| 89 | } | ||||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | 0 | ▶ | sub all_files { | ||||||||||||||||||
|
Subroutine
all_files: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 92 | 0 | my ($self) = @_; | |||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | return [ | ||||||||||||||||||||
| 95 | map File::Spec::Functions::catfile($self->{directory}, $_), | ||||||||||||||||||||
| 96 | $self->{output}, $self->{traces}, $self->{attributes}, | ||||||||||||||||||||
| 97 | 0 | ]; | |||||||||||||||||||
| 98 | } | ||||||||||||||||||||
| 99 | |||||||||||||||||||||
| 100 | 0 | ▶ | sub _errors { | ||||||||||||||||||
|
Subroutine
_errors: not called CC=3 SCAR=24.8
| |||||||||||||||||||||
| 101 | 0 | my ($self) = @_; | |||||||||||||||||||
| 102 | |||||||||||||||||||||
| 103 | 0 | ▶ | return $self->{errors} //= do { | ||||||||||||||||||
|
Condition0%0/3
$self->{"errors"} //= do {
local $/;
$self->{"stderr"} ? readline $self->{"stderr"} : "Command was not run"
}
MC/DC0%0/2
$self->{"errors"} //= do {
local $/;
$self->{"stderr"} ? readline $self->{"stderr"} : "Command was not run"
}
$self->{"errors"}
do {
local $/;
$self->{"stderr"} ? readline $self->{"stderr"} : "Command was not run"
}
Truth table0%0/3
A //= B
A= $self->{"errors"}B= do {
local $/;
$self->{"stderr"} ? readline $self->{"stderr"} : "Command was not run"
}
| |||||||||||||||||||||
| 104 | 0 | local $/; | |||||||||||||||||||
| 105 | $self->{stderr} ? readline $self->{stderr} : | ||||||||||||||||||||
| 106 | 0 | ▶ | "Command was not run"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 107 | }; | ||||||||||||||||||||
| 108 | } | ||||||||||||||||||||
| 109 | |||||||||||||||||||||
| 110 | 24 | 1; | |||||||||||||||||||
| 111 | |||||||||||||||||||||
| 112 | __END__ | ||||||||||||||||||||