« blib/lib/Devel/StatProfiler/FlameGraph.pm
↑ Summary
blib/lib/Devel/StatProfiler/EvalSourceStorage.pm »
| 1 | package Devel::StatProfiler::Aggregator; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: aggregate profiler output into one or more reports | ||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||
| 4 | 15 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 15 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 15 | ▶ | use Devel::StatProfiler::Reader; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 15 | ▶ | use Devel::StatProfiler::SectionChangeReader; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 15 | ▶ | use Devel::StatProfiler::Report; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 15 | ▶ | use Devel::StatProfiler::EvalSource; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 15 | ▶ | use Devel::StatProfiler::SourceMap; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 15 | ▶ | use Devel::StatProfiler::Metadata; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 15 | ▶ | use Devel::StatProfiler::Aggregate; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 15 | ▶ | use Devel::StatProfiler::Utils qw( | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | check_serializer | ||||||||||||||||||||||||||||||||||||||||||
| 16 | read_data | ||||||||||||||||||||||||||||||||||||||||||
| 17 | state_dir | ||||||||||||||||||||||||||||||||||||||||||
| 18 | state_file | ||||||||||||||||||||||||||||||||||||||||||
| 19 | write_data | ||||||||||||||||||||||||||||||||||||||||||
| 20 | write_data_part | ||||||||||||||||||||||||||||||||||||||||||
| 21 | 15 | ); | |||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 15 | ▶ | use File::Glob qw(bsd_glob); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 15 | ▶ | use File::Path (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 15 | ▶ | use File::Basename (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 15 | ▶ | use Errno; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 15 | my $MAIN_REPORT_ID = ['__main__']; | |||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | 1947 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=6 SCAR=18.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 1947 | my ($class, %opts) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 33 | 1947 | ▶ | my $mapper = $opts{mapper} && $opts{mapper}->can_map ? $opts{mapper} : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$opts{"mapper"} and $opts{"mapper"}->can_map
MC/DC50%1/2
$opts{"mapper"} and $opts{"mapper"}->can_map
$opts{"mapper"}
$opts{"mapper"}->can_map
Truth table66%2/3
A and B
A= $opts{"mapper"}B= $opts{"mapper"}->can_map
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | my $self = bless { | ||||||||||||||||||||||||||||||||||||||||||
| 35 | root_dir => $opts{root_directory}, | ||||||||||||||||||||||||||||||||||||||||||
| 36 | parts_dir => $opts{parts_directory} // $opts{root_directory}, | ||||||||||||||||||||||||||||||||||||||||||
| 37 | shard => $opts{shard}, | ||||||||||||||||||||||||||||||||||||||||||
| 38 | shards => $opts{shards} || [$opts{shard}], | ||||||||||||||||||||||||||||||||||||||||||
| 39 | slowops => $opts{slowops}, | ||||||||||||||||||||||||||||||||||||||||||
| 40 | flamegraph => $opts{flamegraph}, | ||||||||||||||||||||||||||||||||||||||||||
| 41 | serializer => $opts{serializer} || 'storable', | ||||||||||||||||||||||||||||||||||||||||||
| 42 | processed => {}, | ||||||||||||||||||||||||||||||||||||||||||
| 43 | reports => {}, | ||||||||||||||||||||||||||||||||||||||||||
| 44 | partial => {}, | ||||||||||||||||||||||||||||||||||||||||||
| 45 | source => Devel::StatProfiler::EvalSource->new( | ||||||||||||||||||||||||||||||||||||||||||
| 46 | serializer => $opts{serializer}, | ||||||||||||||||||||||||||||||||||||||||||
| 47 | root_directory => $opts{root_directory}, | ||||||||||||||||||||||||||||||||||||||||||
| 48 | shard => $opts{shard}, | ||||||||||||||||||||||||||||||||||||||||||
| 49 | genealogy => {}, | ||||||||||||||||||||||||||||||||||||||||||
| 50 | ), | ||||||||||||||||||||||||||||||||||||||||||
| 51 | sourcemap => Devel::StatProfiler::SourceMap->new( | ||||||||||||||||||||||||||||||||||||||||||
| 52 | serializer => $opts{serializer}, | ||||||||||||||||||||||||||||||||||||||||||
| 53 | root_directory => $opts{root_directory}, | ||||||||||||||||||||||||||||||||||||||||||
| 54 | shard => $opts{shard}, | ||||||||||||||||||||||||||||||||||||||||||
| 55 | ), | ||||||||||||||||||||||||||||||||||||||||||
| 56 | metadata => Devel::StatProfiler::Metadata->new( | ||||||||||||||||||||||||||||||||||||||||||
| 57 | serializer => $opts{serializer}, | ||||||||||||||||||||||||||||||||||||||||||
| 58 | root_directory => $opts{root_directory}, | ||||||||||||||||||||||||||||||||||||||||||
| 59 | shard => $opts{shard}, | ||||||||||||||||||||||||||||||||||||||||||
| 60 | ), | ||||||||||||||||||||||||||||||||||||||||||
| 61 | mapper => $mapper, | ||||||||||||||||||||||||||||||||||||||||||
| 62 | mixed_process=> $opts{mixed_process}, | ||||||||||||||||||||||||||||||||||||||||||
| 63 | genealogy => {}, | ||||||||||||||||||||||||||||||||||||||||||
| 64 | last_sample => {}, | ||||||||||||||||||||||||||||||||||||||||||
| 65 | parts => [], | ||||||||||||||||||||||||||||||||||||||||||
| 66 | fetchers => $opts{fetchers}, | ||||||||||||||||||||||||||||||||||||||||||
| 67 | now => time, | ||||||||||||||||||||||||||||||||||||||||||
| 68 | timebox => $opts{timebox}, | ||||||||||||||||||||||||||||||||||||||||||
| 69 | 1947 | ▶ | }, $class; | ||||||||||||||||||||||||||||||||||||||||
|
Condition57%4/7
$opts{"parts_directory"} // $opts{"root_directory"}
$opts{'shards'} || [$opts{'shard'}]
$opts{'serializer'} || 'storable'
MC/DC0%0/2
$opts{"parts_directory"} // $opts{"root_directory"}
$opts{"parts_directory"}
$opts{"root_directory"}
MC/DC0%0/1
$opts{'shards'} || [$opts{'shard'}]
$opts{'shards'}
MC/DC0%0/1
$opts{'serializer'} || 'storable'
$opts{'serializer'}
Truth table66%2/3
A // B
A= $opts{"parts_directory"}B= $opts{"root_directory"}
Truth table50%1/2
A
A= $opts{'shards'}
Truth table50%1/2
A
A= $opts{'serializer'}
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | 1947 | check_serializer($self->{serializer}); | |||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | 1947 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | 3525 | ▶ | sub can_process_trace_file { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
can_process_trace_file: called CC=8 SCAR=21.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 3525 | my ($self, @files) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | return grep { | ||||||||||||||||||||||||||||||||||||||||||
| 80 | 3525 | my $r = eval { | |||||||||||||||||||||||||||||||||||||||||
| 81 | ref $_ ? $_ : Devel::StatProfiler::Reader->new($_, $self->{mapper}) | ||||||||||||||||||||||||||||||||||||||||||
| 82 | 3525 | ▶ | } or do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | 1 | my $errno = $!; | |||||||||||||||||||||||||||||||||||||||||
| 84 | 1 | my $error = $@; | |||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | 1 | ▶ | if ($error !~ /^Failed to open file/ || $errno != Errno::ENOENT) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $error =~ /^Failed to open file/ or $errno != 2
MC/DC0%0/2
not $error =~ /^Failed to open file/ or $errno != 2
not $error =~ /^Failed to open file/
$errno != 2
Truth table33%1/3
not(A) or B
A= not $error =~ /^Failed to open file/B= $errno != 2
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | die; | |||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||
| 89 | 1 | 0; | |||||||||||||||||||||||||||||||||||||||||
| 90 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | 3525 | ▶ | if ($r) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | my ($process_id, $process_ordinal, $parent_id, $parent_ordinal) = | ||||||||||||||||||||||||||||||||||||||||||
| 94 | 3524 | @{$r->get_genealogy_info}; | |||||||||||||||||||||||||||||||||||||||||
| 95 | 3524 | ▶ | my $state = $self->_state($process_id) // { ordinal => 0 }; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->_state($process_id) // {"ordinal", 0}
MC/DC0%0/1
$self->_state($process_id) // {"ordinal", 0}
$self->_state($process_id)
Truth table50%1/2
A
A= $self->_state($process_id)
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | 3524 | ▶ | $process_ordinal == $state->{ordinal} + 1 && | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$process_ordinal == $state->{'ordinal'} + 1 && $self->_is_processed($parent_id, $parent_ordinal)
MC/DC100%2/2
$process_ordinal == $state->{'ordinal'} + 1 && $self->_is_processed($parent_id, $parent_ordinal)
$process_ordinal == $state->{'ordinal'} + 1
$self->_is_processed($parent_id, $parent_ordinal)
Truth table100%3/3
A && B
A= $process_ordinal == $state->{'ordinal'} + 1B= $self->_is_processed($parent_id, $parent_ordinal)
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | $self->_is_processed($parent_id, $parent_ordinal); | ||||||||||||||||||||||||||||||||||||||||||
| 99 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 100 | 1 | 0; | |||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||
| 102 | } @files; | ||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | 8561 | ▶ | sub process_trace_files { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
process_trace_files: called CC=21 SCAR=30.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | 8561 | my ($self, @files) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 107 | 8561 | ▶ | my $eval_mapper = $self->{mapper} && $self->{mapper}->can_map_eval ? $self->{mapper} : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"mapper"} and $self->{"mapper"}->can_map_eval
MC/DC50%1/2
$self->{"mapper"} and $self->{"mapper"}->can_map_eval
$self->{"mapper"}
$self->{"mapper"}->can_map_eval
Truth table66%2/3
A and B
A= $self->{"mapper"}B= $self->{"mapper"}->can_map_eval
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | 8561 | for my $file (@files) { | |||||||||||||||||||||||||||||||||||||||||
| 110 | 8565 | ▶ | my $r = ref $file ? $file : Devel::StatProfiler::Reader->new($file, $self->{mapper}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | 8565 | my $sc = Devel::StatProfiler::SectionChangeReader->new($r); | |||||||||||||||||||||||||||||||||||||||||
| 112 | my ($process_id, $process_ordinal, $parent_id, $parent_ordinal) = | ||||||||||||||||||||||||||||||||||||||||||
| 113 | 8565 | @{$r->get_genealogy_info}; | |||||||||||||||||||||||||||||||||||||||||
| 114 | 8565 | my $state = $self->_state($process_id); | |||||||||||||||||||||||||||||||||||||||||
| 115 | 8565 | ▶ | next if $process_ordinal != $state->{ordinal} + 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | 7982 | $self->{genealogy}{$process_id}{$process_ordinal} = [$parent_id, $parent_ordinal]; | |||||||||||||||||||||||||||||||||||||||||
| 118 | 7982 | $self->{last_sample}{$process_id} = time; | |||||||||||||||||||||||||||||||||||||||||
| 119 | 7982 | $self->{metadata}->add_entries($r->get_custom_metadata); | |||||||||||||||||||||||||||||||||||||||||
| 120 | 7982 | ▶ | $eval_mapper->update_genealogy($process_id, $process_ordinal, $parent_id, $parent_ordinal) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | if $eval_mapper; | ||||||||||||||||||||||||||||||||||||||||||
| 122 | $self->{source}->update_genealogy($process_id, $process_ordinal, $parent_id, $parent_ordinal) | ||||||||||||||||||||||||||||||||||||||||||
| 123 | 7982 | ▶ | if $self->{source}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | 7982 | ▶ | if (my $reader_state = delete $state->{reader_state}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | 7969 | $r->set_reader_state($reader_state); | |||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||
| 129 | 7982 | my ($died, $error); | |||||||||||||||||||||||||||||||||||||||||
| 130 | eval { | ||||||||||||||||||||||||||||||||||||||||||
| 131 | 7982 | ▶ | while ($sc->read_traces) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 132 | 7975 | ▶ | last if !$sc->sections_changed && %{$sc->get_active_sections}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $sc->sections_changed and %{$sc->get_active_sections;}
MC/DC100%2/2
not $sc->sections_changed and %{$sc->get_active_sections;}
not $sc->sections_changed
%{$sc->get_active_sections;}
Truth table100%3/3
not(A) and B
A= not $sc->sections_changedB= %{$sc->get_active_sections;}
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | 7769 | my ($report_keys, $metadata) = $self->handle_section_change($sc, $sc->get_custom_metadata); | |||||||||||||||||||||||||||||||||||||||||
| 134 | 7769 | ▶ | my $entry = $self->{partial}{"@$report_keys"} ||= { | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{"partial"}{join $", @$report_keys} ||= {"report_keys", $report_keys, "report", $self->_fresh_report}
MC/DC100%1/1
$self->{"partial"}{join $", @$report_keys} ||= {"report_keys", $report_keys, "report", $self->_fresh_report}
$self->{"partial"}{join $", @$report_keys}
Truth table100%2/2
A
A= $self->{"partial"}{join $", @$report_keys}
| |||||||||||||||||||||||||||||||||||||||||||
| 135 | report_keys => $report_keys, | ||||||||||||||||||||||||||||||||||||||||||
| 136 | report => $self->_fresh_report, | ||||||||||||||||||||||||||||||||||||||||||
| 137 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 138 | 7769 | ▶ | if ($state->{report}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 139 | 100 | $entry->{report}->merge($state->{report}); | |||||||||||||||||||||||||||||||||||||||||
| 140 | 100 | $state->{report} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||
| 142 | 7769 | $entry->{report}->add_trace_file($sc); | |||||||||||||||||||||||||||||||||||||||||
| 143 | 7769 | ▶ | $entry->{report}->add_metadata($metadata) if $metadata && %$metadata; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$metadata and %$metadata
MC/DC50%1/2
$metadata and %$metadata
$metadata
%$metadata
Truth table66%2/3
A and B
A= $metadataB= %$metadata
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | 7982 | ▶ | if (!$sc->empty) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 147 | 206 | ▶ | $state->{report} ||= $self->_fresh_report; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$state->{"report"} ||= $self->_fresh_report
MC/DC0%0/2
$state->{"report"} ||= $self->_fresh_report
$state->{"report"}
$self->_fresh_report
Truth table66%2/3
A ||= B
A= $state->{"report"}B= $self->_fresh_report
| |||||||||||||||||||||||||||||||||||||||||||
| 148 | 206 | $state->{report}->add_trace_file($sc); | |||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||
| 150 | 7982 | $state->{ordinal} = $process_ordinal; | |||||||||||||||||||||||||||||||||||||||||
| 151 | 7982 | $state->{reader_state} = $r->get_reader_state; | |||||||||||||||||||||||||||||||||||||||||
| 152 | 7982 | $state->{modified} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 153 | 7982 | $state->{ended} = $r->is_stream_ended; | |||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | 7982 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 156 | 7982 | ▶ | } or do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | $died = 1; | |||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | $error = $@; | |||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | $state->{ended} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 161 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||
| 163 | 7982 | $self->{source}->add_sources_from_reader($r); | |||||||||||||||||||||||||||||||||||||||||
| 164 | 7982 | $self->{sourcemap}->add_sources_from_reader($r); | |||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | 7982 | my $metadata = $r->get_custom_metadata; | |||||||||||||||||||||||||||||||||||||||||
| 167 | $self->{metadata}->set_at_inc($metadata->{"\x00at_inc"}) | ||||||||||||||||||||||||||||||||||||||||||
| 168 | 7982 | ▶ | if $metadata->{"\x00at_inc"}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | 7982 | ▶ | die $error if $died; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | 1942 | ▶ | sub save_part { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
save_part: called CC=10 SCAR=23.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | 1942 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||
| 177 | 1942 | for my $entry (values %{$self->{partial}}) { | |||||||||||||||||||||||||||||||||||||||||
| 178 | 1839 | for my $key (@{$entry->{report_keys}}) { | |||||||||||||||||||||||||||||||||||||||||
| 179 | 1861 | $self->_merge_report($key, $entry->{report}); | |||||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||
| 183 | 1942 | my $state_dir = state_dir($self); | |||||||||||||||||||||||||||||||||||||||||
| 184 | 1942 | my $parts_dir = state_dir($self, 1); | |||||||||||||||||||||||||||||||||||||||||
| 185 | 1942 | File::Path::mkpath([$state_dir, $parts_dir]); | |||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||
| 187 | write_data_part($self, $parts_dir, 'genealogy', $self->{genealogy}) | ||||||||||||||||||||||||||||||||||||||||||
| 188 | 1942 | ▶ | if %{$self->{genealogy}}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 189 | write_data_part($self, $parts_dir, 'last_sample', $self->{last_sample}) | ||||||||||||||||||||||||||||||||||||||||||
| 190 | 1942 | ▶ | if %{$self->{last_sample}}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||
| 192 | 1942 | for my $process_id (keys %{$self->{processed}}) { | |||||||||||||||||||||||||||||||||||||||||
| 193 | 1944 | my $processed = $self->{processed}{$process_id}; | |||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||
| 195 | 1944 | ▶ | next unless $processed->{modified}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 196 | 1943 | ▶ | if ($processed->{ended}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 197 | 12 | unlink state_file($self, 0, "processed.$process_id"); | |||||||||||||||||||||||||||||||||||||||||
| 198 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 199 | 1931 | write_data($self, $state_dir, "processed.$process_id", $processed); | |||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||
| 203 | 1942 | $self->{metadata}->save_part($parts_dir); | |||||||||||||||||||||||||||||||||||||||||
| 204 | 1942 | $self->{source}->save_part($parts_dir); | |||||||||||||||||||||||||||||||||||||||||
| 205 | 1942 | $self->{sourcemap}->save_part($parts_dir); | |||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||
| 207 | 1942 | for my $key (keys %{$self->{reports}}) { | |||||||||||||||||||||||||||||||||||||||||
| 208 | my $report_dir = File::Spec::Functions::catdir( | ||||||||||||||||||||||||||||||||||||||||||
| 209 | 1859 | $self->{parts_dir}, $key, 'parts', | |||||||||||||||||||||||||||||||||||||||||
| 210 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 211 | # writes some genealogy and source data twice, but it's OK for now | ||||||||||||||||||||||||||||||||||||||||||
| 212 | 1859 | $self->{reports}{$key}->save_part($report_dir); | |||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||
| 215 | 1942 | my $shard_marker = File::Spec::Functions::catfile($state_dir, "shard.$self->{shard}"); | |||||||||||||||||||||||||||||||||||||||||
| 216 | 1942 | ▶ | unless (-f $shard_marker) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 217 | 11 | open my $fh, '>', $shard_marker; | |||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||
| 221 | 1861 | ▶ | sub _merge_report { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_merge_report: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||
| 222 | 1861 | my ($self, $report_id, $report) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||
| 224 | 1861 | ▶ | $self->{reports}{$report_id} ||= $self->_fresh_report; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$self->{"reports"}{$report_id} ||= $self->_fresh_report
MC/DC0%0/2
$self->{"reports"}{$report_id} ||= $self->_fresh_report
$self->{"reports"}{$report_id}
$self->_fresh_report
Truth table66%2/3
A ||= B
A= $self->{"reports"}{$report_id}B= $self->_fresh_report
| |||||||||||||||||||||||||||||||||||||||||||
| 225 | 1861 | $self->{reports}{$report_id}->merge($report); | |||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||
| 228 | 12089 | ▶ | sub _state { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_state: called CC=9 SCAR=28.5
| |||||||||||||||||||||||||||||||||||||||||||
| 229 | 12089 | my ($self, $process_id) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||
| 231 | 12089 | ▶ | return $self->{processed}{$process_id} //= do { | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$self->{"processed"}{$process_id} //= do {
my $state_file = state_file($self, 0, "processed.$process_id");
my $processed;
if (-f $state_file) {
eval {
do {
$processed = read_data($self->{"serializer"}, $state_file);
$processed->{"modified"} = 0;
1
}
} or do {
my $error = $@ || "Zombie error";
if ($error->isa("autodie::exception") and $error->matches("open") and $error->errno == 2) {
();
}
else {
die;
}
};
};
$processed // {"process_id", $process_id, "ordinal", 0, "report", undef, "reader_state", undef, "modified", 0, "ended", 0}
}
MC/DC0%0/2
$self->{"processed"}{$process_id} //= do {
my $state_file = state_file($self, 0, "processed.$process_id");
my $processed;
if (-f $state_file) {
eval {
do {
$processed = read_data($self->{"serializer"}, $state_file);
$processed->{"modified"} = 0;
1
}
} or do {
my $error = $@ || "Zombie error";
if ($error->isa("autodie::exception") and $error->matches("open") and $error->errno == 2) {
();
}
else {
die;
}
};
};
$processed // {"process_id", $process_id, "ordinal", 0, "report", undef, "reader_state", undef, "modified", 0, "ended", 0}
}
$self->{"processed"}{$process_id}
do {
my $state_file = state_file($self, 0, "processed.$process_id");
my $processed;
if (-f $state_file) {
eval {
do {
$processed = read_data($self->{"serializer"}, $state_file);
$processed->{"modified"} = 0;
1
}
} or do {
my $error = $@ || "Zombie error";
if ($error->isa("autodie::exception") and $error->matches("open") and $error->errno == 2) {
();
}
else {
die;
}
};
};
$processed // {"process_id", $process_id, "ordinal", 0, "report", undef, "reader_state", undef, "modified", 0, "ended", 0}
}
Truth table66%2/3
A //= B
A= $self->{"processed"}{$process_id}B= do {
my $state_file = state_file($self, 0, "processed.$process_id");
my $processed;
if (-f $state_file) {
eval {
do {
$processed = read_data($self->{"serializer"}, $state_file);
$processed->{"modified"} = 0;
1
}
} or do {
my $error = $@ || "Zombie error";
if ($error->isa("autodie::exception") and $error->matches("open") and $error->errno == 2) {
();
}
else {
die;
}
};
};
$processed // {"process_id", $process_id, "ordinal", 0, "report", undef, "reader_state", undef, "modified", 0, "ended", 0}
}
| |||||||||||||||||||||||||||||||||||||||||||
| 232 | 1953 | my $state_file = state_file($self, 0, "processed.$process_id"); | |||||||||||||||||||||||||||||||||||||||||
| 233 | 1953 | my $processed; | |||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||
| 235 | 1953 | ▶ | if (-f $state_file) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 236 | eval { | ||||||||||||||||||||||||||||||||||||||||||
| 237 | 1930 | $processed = read_data($self->{serializer}, $state_file); | |||||||||||||||||||||||||||||||||||||||||
| 238 | 1930 | $processed->{modified} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||
| 240 | 1930 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 241 | 1930 | ▶ | } or do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | ▶ | my $error = $@ || "Zombie error"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$@ || 'Zombie error'
MC/DC0%0/1
$@ || 'Zombie error'
$@
Truth table0%0/2
A
A= $@
| |||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | ▶ | if ($error->isa("autodie::exception") && | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$error->isa("autodie::exception") and $error->matches("open") and $error->errno == 2
$error->isa("autodie::exception") and $error->matches("open")
MC/DC0%0/3
$error->isa("autodie::exception") and $error->matches("open") and $error->errno == 2
$error->isa("autodie::exception")
$error->matches("open")
$error->errno == 2
Truth table0%0/4
A and B and C
A= $error->isa("autodie::exception")B= $error->matches("open")C= $error->errno == 2
| |||||||||||||||||||||||||||||||||||||||||||
| 245 | $error->matches('open') && | ||||||||||||||||||||||||||||||||||||||||||
| 246 | $error->errno == Errno::ENOENT) { | ||||||||||||||||||||||||||||||||||||||||||
| 247 | # silently ignore, it might have been cleaned up by | ||||||||||||||||||||||||||||||||||||||||||
| 248 | # another process | ||||||||||||||||||||||||||||||||||||||||||
| 249 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | die; | |||||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||||||
| 252 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||
| 255 | # initial state | ||||||||||||||||||||||||||||||||||||||||||
| 256 | $processed // { | ||||||||||||||||||||||||||||||||||||||||||
| 257 | 1953 | ▶ | process_id => $process_id, | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$processed // {"process_id", $process_id, "ordinal", 0, "report", undef, "reader_state", undef, "modified", 0, "ended", 0}
MC/DC100%1/1
$processed // {"process_id", $process_id, "ordinal", 0, "report", undef, "reader_state", undef, "modified", 0, "ended", 0}
$processed
Truth table100%2/2
A
A= $processed
| |||||||||||||||||||||||||||||||||||||||||||
| 258 | ordinal => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 259 | report => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 260 | reader_state => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 261 | modified => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 262 | ended => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 263 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 264 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||
| 267 | 1182 | ▶ | sub _is_processed { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_processed: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 268 | 1182 | my ($self, $process_id, $process_ordinal) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 269 | 1182 | ▶ | my $eval_mapper = $self->{mapper} && $self->{mapper}->can_map_eval ? $self->{mapper} : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"mapper"} and $self->{"mapper"}->can_map_eval
MC/DC50%1/2
$self->{"mapper"} and $self->{"mapper"}->can_map_eval
$self->{"mapper"}
$self->{"mapper"}->can_map_eval
Truth table66%2/3
A and B
A= $self->{"mapper"}B= $self->{"mapper"}->can_map_eval
| |||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||
| 271 | 1182 | ▶ | return 1 if !$eval_mapper; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 272 | 18 | return $eval_mapper->is_processed($process_id, $process_ordinal); | |||||||||||||||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||
| 275 | 3784 | ▶ | sub _merge_genealogy { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_merge_genealogy: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 276 | 3784 | my ($self, $genealogy) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||
| 278 | 3784 | for my $process_id (keys %$genealogy) { | |||||||||||||||||||||||||||||||||||||||||
| 279 | 3788 | my $item = $genealogy->{$process_id}; | |||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||
| 281 | 3788 | @{$self->{genealogy}{$process_id}}{keys %$item} = values %$item; | |||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||
| 285 | 10 | ▶ | sub _clone_genealogy { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_clone_genealogy: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 286 | 10 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 287 | 10 | my $genealogy = $self->{genealogy}; | |||||||||||||||||||||||||||||||||||||||||
| 288 | 10 | my $res = {}; | |||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||
| 290 | 10 | for my $process_id (keys %$genealogy) { | |||||||||||||||||||||||||||||||||||||||||
| 291 | 8 | my $item = $genealogy->{$process_id}; | |||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||
| 293 | 8 | @{$res->{$process_id}}{keys %$item} = values %$item; | |||||||||||||||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||
| 296 | 10 | return $res; | |||||||||||||||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||
| 299 | 1936 | ▶ | sub _merge_last_sample { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_merge_last_sample: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 300 | 1936 | my ($self, $last_sample) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||
| 302 | 1936 | for my $process_id (keys %$last_sample) { | |||||||||||||||||||||||||||||||||||||||||
| 303 | 1937 | my $new = $last_sample->{$process_id}; | |||||||||||||||||||||||||||||||||||||||||
| 304 | 1937 | ▶ | my $current = $self->{last_sample}{$process_id} // 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{"last_sample"}{$process_id} // 0
MC/DC100%1/1
$self->{"last_sample"}{$process_id} // 0
$self->{"last_sample"}{$process_id}
Truth table100%2/2
A
A= $self->{"last_sample"}{$process_id}
| |||||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||
| 306 | 1937 | ▶ | $self->{last_sample}{$process_id} = $new > $current ? $new : $current; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||
| 310 | 50 | ▶ | sub _all_data_files { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_all_data_files: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 311 | 50 | my ($self, $parts, $kind) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 312 | 50 | my (@merged); | |||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||
| 314 | 50 | ▶ | for my $shard ($self->{shard} ? ($self->{shard}) : @{$self->{shards}}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 315 | 50 | my $info = {root_dir => $self->{root_dir}, shard => $shard}; | |||||||||||||||||||||||||||||||||||||||||
| 316 | 50 | my $merged = state_file($info, 0, $kind); | |||||||||||||||||||||||||||||||||||||||||
| 317 | 50 | ▶ | push @merged, (-f $merged ? $merged : ()); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||||||||||||
| 319 | 50 | ▶ | my @parts = $parts ? bsd_glob state_file($self, 1, "*/$kind.*") : (); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||
| 321 | 50 | return (\@parts, \@merged); | |||||||||||||||||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||
| 324 | 10 | ▶ | sub _load_metadata { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_load_metadata: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 325 | 10 | my ($self, $parts) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 326 | my $metadata = $self->{metadata} = Devel::StatProfiler::Metadata->new( | ||||||||||||||||||||||||||||||||||||||||||
| 327 | serializer => $self->{serializer}, | ||||||||||||||||||||||||||||||||||||||||||
| 328 | root_directory => $self->{root_dir}, | ||||||||||||||||||||||||||||||||||||||||||
| 329 | shard => $self->{shard}, | ||||||||||||||||||||||||||||||||||||||||||
| 330 | 10 | ); | |||||||||||||||||||||||||||||||||||||||||
| 331 | 10 | my ($metadata_parts, $metadata_merged) = _all_data_files($self, $parts, 'metadata'); | |||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||
| 333 | 10 | $metadata->load_and_merge(@$metadata_merged, @$metadata_parts); | |||||||||||||||||||||||||||||||||||||||||
| 334 | 10 | push @{$self->{parts}}, @$metadata_parts; | |||||||||||||||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||
| 337 | 10 | ▶ | sub _load_genealogy { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_load_genealogy: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 338 | 10 | my ($self, $parts) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 339 | 10 | my ($genealogy_parts, $genealogy_merged) = _all_data_files($self, $parts, 'genealogy'); | |||||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||||||
| 341 | $self->_merge_genealogy(read_data($self->{serializer}, $_)) | ||||||||||||||||||||||||||||||||||||||||||
| 342 | 10 | for @$genealogy_merged, @$genealogy_parts; | |||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||
| 344 | 10 | push @{$self->{parts}}, @$genealogy_parts; | |||||||||||||||||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||||
| 347 | 10 | ▶ | sub _load_last_sample { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_load_last_sample: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 348 | 10 | my ($self, $parts) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 349 | 10 | my ($last_sample_parts, $last_sample_merged) = _all_data_files($self, $parts, 'last_sample'); | |||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||
| 351 | $self->_merge_last_sample(read_data($self->{serializer}, $_)) | ||||||||||||||||||||||||||||||||||||||||||
| 352 | 10 | for @$last_sample_merged, @$last_sample_parts; | |||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||
| 354 | 10 | push @{$self->{parts}}, @$last_sample_parts; | |||||||||||||||||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||||||
| 357 | 10 | ▶ | sub _load_source { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_load_source: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 358 | 10 | my ($self, $parts) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 359 | my $source = $self->{source} = Devel::StatProfiler::EvalSource->new( | ||||||||||||||||||||||||||||||||||||||||||
| 360 | serializer => $self->{serializer}, | ||||||||||||||||||||||||||||||||||||||||||
| 361 | root_directory => $self->{root_dir}, | ||||||||||||||||||||||||||||||||||||||||||
| 362 | shard => $self->{shard}, | ||||||||||||||||||||||||||||||||||||||||||
| 363 | 10 | genealogy => $self->_clone_genealogy, | |||||||||||||||||||||||||||||||||||||||||
| 364 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 365 | 10 | my ($source_parts, $source_merged) = _all_data_files($self, $parts, 'source'); | |||||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||||||
| 367 | 10 | $source->load_and_merge(@$source_merged, @$source_parts); | |||||||||||||||||||||||||||||||||||||||||
| 368 | 10 | push @{$self->{parts}}, @$source_parts; | |||||||||||||||||||||||||||||||||||||||||
| 369 | } | ||||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||
| 371 | 10 | ▶ | sub _load_sourcemap { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_load_sourcemap: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 372 | 10 | my ($self, $parts) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 373 | my $sourcemap = $self->{sourcemap} = Devel::StatProfiler::SourceMap->new( | ||||||||||||||||||||||||||||||||||||||||||
| 374 | serializer => $self->{serializer}, | ||||||||||||||||||||||||||||||||||||||||||
| 375 | root_directory => $self->{root_dir}, | ||||||||||||||||||||||||||||||||||||||||||
| 376 | shard => $self->{shard}, | ||||||||||||||||||||||||||||||||||||||||||
| 377 | 10 | ); | |||||||||||||||||||||||||||||||||||||||||
| 378 | 10 | my ($sourcemap_parts, $sourcemap_merged) = _all_data_files($self, $parts, 'sourcemap'); | |||||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||||||
| 380 | 10 | $sourcemap->load_and_merge(@$sourcemap_merged, @$sourcemap_parts); | |||||||||||||||||||||||||||||||||||||||||
| 381 | 10 | push @{$self->{parts}}, @$sourcemap_parts; | |||||||||||||||||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||||||
| 384 | 17 | ▶ | sub _load_all_metadata { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_load_all_metadata: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 385 | 17 | my ($self, $parts) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||
| 387 | 17 | ▶ | return if $self->{genealogy} && %{$self->{genealogy}}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->{"genealogy"} and %{$self->{"genealogy"};}
MC/DC100%2/2
$self->{"genealogy"} and %{$self->{"genealogy"};}
$self->{"genealogy"}
%{$self->{"genealogy"};}
Truth table100%3/3
A and B
A= $self->{"genealogy"}B= %{$self->{"genealogy"};}
| |||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||
| 389 | 10 | $self->_load_metadata($parts); | |||||||||||||||||||||||||||||||||||||||||
| 390 | 10 | $self->_load_genealogy($parts); | |||||||||||||||||||||||||||||||||||||||||
| 391 | 10 | $self->_load_last_sample($parts); | |||||||||||||||||||||||||||||||||||||||||
| 392 | 10 | $self->_load_source($parts); | |||||||||||||||||||||||||||||||||||||||||
| 393 | 10 | $self->_load_sourcemap($parts); | |||||||||||||||||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||
| 396 | 3 | ▶ | sub merge_metadata { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
merge_metadata: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 397 | 3 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||
| 399 | 3 | $self->_load_all_metadata('parts'); | |||||||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||||||||
| 401 | 3 | $self->{metadata}->save_merged; | |||||||||||||||||||||||||||||||||||||||||
| 402 | 3 | $self->{source}->save_merged; | |||||||||||||||||||||||||||||||||||||||||
| 403 | 3 | $self->{sourcemap}->save_merged; | |||||||||||||||||||||||||||||||||||||||||
| 404 | 3 | write_data($self, state_dir($self), 'last_sample', $self->{last_sample}); | |||||||||||||||||||||||||||||||||||||||||
| 405 | # genealogy needs to be saved last, because can_process_trace_files | ||||||||||||||||||||||||||||||||||||||||||
| 406 | # assumes that if there is the genealogy the rest has been saved | ||||||||||||||||||||||||||||||||||||||||||
| 407 | 3 | write_data($self, state_dir($self), 'genealogy', $self->{genealogy}); | |||||||||||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||||||||||||
| 409 | 3 | for my $part (@{$self->{parts}}) { | |||||||||||||||||||||||||||||||||||||||||
| 410 | 4426 | unlink $part; | |||||||||||||||||||||||||||||||||||||||||
| 411 | } | ||||||||||||||||||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||
| 414 | 1491 | ▶ | sub merge_report { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
merge_report: called CC=11 SCAR=24.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 415 | 1491 | my ($self, $report_id, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||||||
| 417 | 1491 | ▶ | $self->_load_all_metadata('parts') if $args{with_metadata}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||||||||||
| 419 | 1491 | my $suffix = $self->_suffix; | |||||||||||||||||||||||||||||||||||||||||
| 420 | 1491 | my @report_parts = bsd_glob File::Spec::Functions::catfile($self->{parts_dir}, $report_id, 'parts', '*', "report.*.$self->{shard}.*"); | |||||||||||||||||||||||||||||||||||||||||
| 421 | 1491 | my @metadata_parts = bsd_glob File::Spec::Functions::catfile($self->{parts_dir}, $report_id, 'parts', '*', "metadata.$self->{shard}.*"); | |||||||||||||||||||||||||||||||||||||||||
| 422 | 1491 | my $report_merged = File::Spec::Functions::catfile($self->{root_dir}, $report_id, "report.$suffix.$self->{shard}"); | |||||||||||||||||||||||||||||||||||||||||
| 423 | 1491 | my $metadata_merged = File::Spec::Functions::catfile($self->{root_dir}, $report_id, "metadata.$self->{shard}"); | |||||||||||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||||||||||||
| 425 | 1491 | my $res = $self->_fresh_report(mixed_process => 1); | |||||||||||||||||||||||||||||||||||||||||
| 426 | 1491 | my $parts = $self->_fresh_report(mixed_process => 1); | |||||||||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||||||||||
| 428 | # TODO fix this incestuous relation | ||||||||||||||||||||||||||||||||||||||||||
| 429 | 1491 | $res->{source} = $self->{source}; | |||||||||||||||||||||||||||||||||||||||||
| 430 | 1491 | $res->{sourcemap} = $self->{sourcemap}; | |||||||||||||||||||||||||||||||||||||||||
| 431 | 1491 | $res->{genealogy} = $self->{genealogy}; | |||||||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||||||||
| 433 | 1491 | ▶ | if (-f $report_merged) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 434 | 1476 | my $report = $self->_fresh_report; | |||||||||||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||||||||||||
| 436 | 1476 | $report->load($report_merged); | |||||||||||||||||||||||||||||||||||||||||
| 437 | 1476 | $res->merge($report); | |||||||||||||||||||||||||||||||||||||||||
| 438 | } | ||||||||||||||||||||||||||||||||||||||||||
| 439 | 0 | $res->remap_names(@{$args{remap}}) | |||||||||||||||||||||||||||||||||||||||||
| 440 | 1491 | ▶ | if $args{remap} && $args{remap_again}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$args{"remap"} and $args{"remap_again"}
MC/DC0%0/2
$args{"remap"} and $args{"remap_again"}
$args{"remap"}
$args{"remap_again"}
Truth table33%1/3
A and B
A= $args{"remap"}B= $args{"remap_again"}
| |||||||||||||||||||||||||||||||||||||||||||
| 441 | 1491 | for my $file (grep -f $_, @report_parts) { | |||||||||||||||||||||||||||||||||||||||||
| 442 | 1858 | my $report = $self->_fresh_report; | |||||||||||||||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||||||||||||||||
| 444 | 1858 | $report->load($file); | |||||||||||||||||||||||||||||||||||||||||
| 445 | 1858 | $parts->merge($report); | |||||||||||||||||||||||||||||||||||||||||
| 446 | } | ||||||||||||||||||||||||||||||||||||||||||
| 447 | 0 | $parts->remap_names(@{$args{remap}}) | |||||||||||||||||||||||||||||||||||||||||
| 448 | 1491 | ▶ | if $args{remap}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 449 | 1491 | ▶ | $res->merge($parts) if $parts->{tick}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||||||||||||||||
| 451 | 1491 | for my $file (grep -f $_, ($metadata_merged, @metadata_parts)) { | |||||||||||||||||||||||||||||||||||||||||
| 452 | 377 | $res->load_and_merge_metadata($file); | |||||||||||||||||||||||||||||||||||||||||
| 453 | } | ||||||||||||||||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||||||||||||||||
| 455 | 1491 | my $report_dir = File::Spec::Functions::catdir($self->{root_dir}, $report_id); | |||||||||||||||||||||||||||||||||||||||||
| 456 | 1491 | $res->save_aggregate($report_dir); | |||||||||||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||||||||||||
| 458 | 1491 | ▶ | $res->add_metadata($self->global_metadata) if $args{with_metadata}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||||||||||||
| 460 | 1491 | for my $part (@report_parts, @metadata_parts) { | |||||||||||||||||||||||||||||||||||||||||
| 461 | 2235 | unlink $part; | |||||||||||||||||||||||||||||||||||||||||
| 462 | } | ||||||||||||||||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||||||||||||||||
| 464 | 1491 | return $res; | |||||||||||||||||||||||||||||||||||||||||
| 465 | } | ||||||||||||||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||||||||||||||
| 467 | 11605 | ▶ | sub _suffix { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_suffix: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 468 | 11605 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||||||||||||
| 470 | 11605 | ▶ | return $self->{timebox} ? $self->{now} - $self->{now} % $self->{timebox} : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 471 | } | ||||||||||||||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||||||||||||
| 473 | 10114 | ▶ | sub _fresh_report { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_fresh_report: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 474 | 10114 | my ($self, %opts) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||||||||||||||||
| 476 | return Devel::StatProfiler::Report->new( | ||||||||||||||||||||||||||||||||||||||||||
| 477 | slowops => $self->{slowops}, | ||||||||||||||||||||||||||||||||||||||||||
| 478 | flamegraph => $self->{flamegraph}, | ||||||||||||||||||||||||||||||||||||||||||
| 479 | serializer => $self->{serializer}, | ||||||||||||||||||||||||||||||||||||||||||
| 480 | sources => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 481 | root_directory => $self->{root_dir}, | ||||||||||||||||||||||||||||||||||||||||||
| 482 | parts_directory=> $self->{parts_dir}, | ||||||||||||||||||||||||||||||||||||||||||
| 483 | shard => $self->{shard}, | ||||||||||||||||||||||||||||||||||||||||||
| 484 | mixed_process => $opts{mixed_process} // $self->{mixed_process}, | ||||||||||||||||||||||||||||||||||||||||||
| 485 | 10114 | ▶ | suffix => $self->_suffix, | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$opts{"mixed_process"} // $self->{"mixed_process"}
MC/DC100%2/2
$opts{"mixed_process"} // $self->{"mixed_process"}
$opts{"mixed_process"}
$self->{"mixed_process"}
Truth table100%3/3
A // B
A= $opts{"mixed_process"}B= $self->{"mixed_process"}
| |||||||||||||||||||||||||||||||||||||||||||
| 486 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 487 | } | ||||||||||||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||||||||||||
| 489 | 0 | ▶ | sub add_report_metadata { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_report_metadata: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 490 | 0 | my ($self, $report_id, $metadata) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||||||||||||||||
| 492 | 0 | my $report_dir = File::Spec::Functions::catdir($self->{parts_dir}, $report_id, 'parts'); | |||||||||||||||||||||||||||||||||||||||||
| 493 | my $report_metadata = Devel::StatProfiler::Metadata->new( | ||||||||||||||||||||||||||||||||||||||||||
| 494 | serializer => $self->{serializer}, | ||||||||||||||||||||||||||||||||||||||||||
| 495 | root_directory => $self->{root_dir}, | ||||||||||||||||||||||||||||||||||||||||||
| 496 | shard => $self->{shard}, | ||||||||||||||||||||||||||||||||||||||||||
| 497 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||
| 498 | 0 | $report_metadata->add_entries($metadata); | |||||||||||||||||||||||||||||||||||||||||
| 499 | 0 | $report_metadata->save_report_part($report_dir); | |||||||||||||||||||||||||||||||||||||||||
| 500 | } | ||||||||||||||||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||||||||||||||||
| 502 | 12 | ▶ | sub global_metadata { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
global_metadata: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 503 | 12 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||||||||||||||||
| 505 | 12 | return $self->{metadata}->get; | |||||||||||||||||||||||||||||||||||||||||
| 506 | } | ||||||||||||||||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||||||||||||||||
| 508 | 459 | ▶ | sub add_global_metadata { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_global_metadata: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 509 | 459 | my ($self, $metadata) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||||||||||||||||
| 511 | 459 | $self->{metadata}->add_entry($_, $metadata->{$_}) for keys %$metadata; | |||||||||||||||||||||||||||||||||||||||||
| 512 | } | ||||||||||||||||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||||||||||||||||
| 514 | 7061 | ▶ | sub handle_section_change { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
handle_section_change: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 515 | 7061 | my ($self, $sc, $state) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||||||||||
| 517 | 7061 | return $MAIN_REPORT_ID; | |||||||||||||||||||||||||||||||||||||||||
| 518 | } | ||||||||||||||||||||||||||||||||||||||||||
| 519 | |||||||||||||||||||||||||||||||||||||||||||
| 520 | # temporary during refactoring | ||||||||||||||||||||||||||||||||||||||||||
| 521 | 15 | *all_unmerged_reports = \&Devel::StatProfiler::Aggregate::all_unmerged_reports; | |||||||||||||||||||||||||||||||||||||||||
| 522 | 15 | *_all_reports = \&Devel::StatProfiler::Aggregate::_all_reports; | |||||||||||||||||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||||||||||||||||
| 524 | 15 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||||||||||||||||
| 526 | __END__ | ||||||||||||||||||||||||||||||||||||||||||