Skip to content

Commit

Permalink
Improved handling/reporting of child process exit reason.
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Cox <[email protected]>
  • Loading branch information
henry2cox committed Oct 19, 2023
1 parent 663f0bc commit 4bd5094
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 51 deletions.
15 changes: 8 additions & 7 deletions bin/genhtml
Original file line number Diff line number Diff line change
Expand Up @@ -5131,7 +5131,8 @@ sub merge_child($$$)
$f = "unable to open $f: $!";
if (0 == $childstatus) {
lcovutil::report_parallel_error('lcov',
$lcovutil::ERROR_PARALLEL, $f, keys(%$children));
$lcovutil::ERROR_PARALLEL, $childPid, 0, $f,
keys(%$children));
}
}
}
Expand Down Expand Up @@ -5185,18 +5186,18 @@ sub merge_child($$$)
}
};
if ($@) {
$childstatus = 1 unless $childstatus;
$childstatus = 1 << 8 unless $childstatus;
print(STDERR $@);
lcovutil::report_parallel_error('genhtml',
$lcovutil::ERROR_PARALLEL,
"unable to deserialize $dumpfile: $@",
keys(%$children));
$lcovutil::ERROR_PARALLEL, $childPid, $childstatus,
"unable to deserialize $dumpfile: $@",
keys(%$children));
}
}
if (0 != $childstatus) {
lcovutil::report_parallel_error('genhtml', $lcovutil::ERROR_CHILD,
"error in child $childPid processing: non-zero code $childstatus",
keys(%$children));
$childPid, $childstatus, "error during child processing",
keys(%$children));
}
my $end = Time::HiRes::gettimeofday();
$lcovutil::profileData{$type}{$fullname} = $end - $start;
Expand Down
18 changes: 8 additions & 10 deletions bin/geninfo
Original file line number Diff line number Diff line change
Expand Up @@ -977,7 +977,7 @@ sub _merge_one_child($$$$$)
} else {
$f = "unable to open $f: $!";
if (0 == $childstatus) {
report_parallel_error('geninfo', $ERROR_PARALLEL,
report_parallel_error('geninfo', $ERROR_PARALLEL, $child, 0,
$f, keys(%$children));
}
}
Expand Down Expand Up @@ -1018,19 +1018,17 @@ sub _merge_one_child($$$$$)
$intervalMonitor->checkUpdate($processedFiles);
};
if ($@) {
$childstatus = 1 unless $childstatus;
$childstatus = 1 << 8 unless $childstatus;
print STDOUT $@;
report_parallel_error('geninfo', $ERROR_PARALLEL,
"unable to deserialize $dumped: $@",
keys(%$children));
report_parallel_error('geninfo', $ERROR_PARALLEL, $child,
$childstatus, "unable to deserialize $dumped: $@",
keys(%$children));
}
}
if ($childstatus != 0) {
report_parallel_error(
'geninfo',
$ERROR_CHILD,
"error in child processing: non-zero code $childstatus: ignoring data in chunk $chunkId",
keys(%$children));
report_parallel_error('geninfo', $ERROR_CHILD, $child, $childstatus,
"ignoring data in chunk $chunkId",
keys(%$children));
}
foreach my $f ($dumped) {
unlink $f
Expand Down
91 changes: 57 additions & 34 deletions lib/lcovutil.pm
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use Digest::MD5 qw(md5_base64);
use FindBin;
use Getopt::Long;
use DateTime;
use Config;

our @ISA = qw(Exporter);
our @EXPORT_OK = qw($tool_name $tool_dir $lcov_version $lcov_url
Expand Down Expand Up @@ -1755,15 +1756,26 @@ sub ignorable_warning($$;$)

sub report_parallel_error
{
my $operation = shift;
my $errno = shift;
my $msg = shift;
my $operation = shift;
my $errno = shift;
my $id = shift;
my $childstatus = shift;
my $msg = shift;
# kill all my remaining children so user doesn't see unexpected console
# messages from dangling children (who cannot open files because the
# temp directory has been deleted, and so forth)
kill(9, @_) if @_ && !is_ignored($errno);
my $status = $childstatus >> 8 if $childstatus;
my $signal = $childstatus & 0xFF if $childstatus;
my $explain = " child $id returned non-zero exit status $status"
if defined($childstatus);
$explain =
" child $id died died due to signal $signal (SIG" .
(split(' ', $Config{sig_name}))[$signal] .
'): possibly killed by OS due to out-of-memory - see --memory and --parallel options for throttling'
if defined($signal) && $signal;
ignorable_error($errno,
"$operation: error '$msg' during child processing (try removing the '--parallel' option)"
"$operation: error '$msg': $explain (try removing the '--parallel' option)"
);
}

Expand Down Expand Up @@ -5353,8 +5365,8 @@ sub _mergeParallelChunk
} else {
$f = "unable to open $f: $!";
if (0 == $childstatus) {
lcovutil::report_parallel_error($lcovutil::tool_name,
$ERROR_PARALLEL, $f, keys(%$children));
lcovutil::report_parallel_error('filter',
$ERROR_PARALLEL, $child, 0, $f, keys(%$children));
}
}
}
Expand Down Expand Up @@ -5394,21 +5406,26 @@ sub _mergeParallelChunk
#$intervalMonitor->checkUpdate($processedFiles);

} else {
lcovutil::report_parallel_error($lcovutil::tool_name,
$ERROR_PARALLEL, "unable to deserialize $dumped: $@",
, keys(%$children));
lcovutil::report_parallel_error('filter',
$ERROR_PARALLEL, $child, $childstatus,
"unable to deserialize $dumped: $@",
, keys(%$children));
}
} else {
lcovutil::report_parallel_error('filter',
$ERROR_PARALLEL, $child, $childstatus,
"serialized data '$dumped' not presetnt",
, keys(%$children));
}

foreach my $f ($dumped) {
unlink $f
if -f $f;
}
if ($childstatus != 0) {
lcovutil::report_parallel_error(
$lcovutil::tool_name,
$ERROR_CHILD,
"child $child returned non-zero code $childstatus: ignoring data in chunk $chunkId",
keys(%$children));
lcovutil::report_parallel_error('filter', $ERROR_CHILD, $child,
$childstatus, "ignoring data in chunk $chunkId",
keys(%$children));
}
my $to = Time::HiRes::gettimeofday();
$lcovutil::profileData{filt_chunk}{$chunkId} = $to - $forkAt;
Expand Down Expand Up @@ -5641,10 +5658,9 @@ sub _processFilterWorklist
$childstatus, \@save);
};
if ($@) {
$childstatus = 1 unless $childstatus;
lcovutil::report_parallel_error($lcovutil::tool_name,
$lcovutil::ERROR_CHILD,
"child returned non-zero exit code $childstatus: $@");
$childstatus = 1 << 8 unless $childstatus;
lcovutil::report_parallel_error('filter',
$lcovutil::ERROR_CHILD, $child, $childstatus, $@);
}
--$currentParallel;
}
Expand Down Expand Up @@ -5686,10 +5702,9 @@ sub _processFilterWorklist
\@save);
};
if ($@) {
$childstatus = 1 unless $childstatus;
lcovutil::report_parallel_error($lcovutil::tool_name,
$lcovutil::ERROR_CHILD,
"child returned non-zero exit code $childstatus: $@");
$childstatus = 1 << 8 unless $childstatus;
lcovutil::report_parallel_error('filter', $lcovutil::ERROR_CHILD,
$child, $childstatus, $@);
}

}
Expand Down Expand Up @@ -6835,8 +6850,8 @@ sub merge
} else {
$f = "unable to open $f: $!";
if (0 == $childstatus) {
lcovutil::report_parallel_error('lcov', $f,
$ERROR_PARALLEL, keys(%children));
lcovutil::report_parallel_error('aggregate',
$ERROR_PARALLEL, $child, 0, $f, keys(%children));
}
}
}
Expand All @@ -6855,8 +6870,11 @@ sub merge
lcovutil::update_state(@$update);
if ($function_mapping) {
if (!defined($func_map)) {
lcovutil::report_parallel_error('lcov',
lcovutil::report_parallel_error(
'aggregate',
$ERROR_PARALLEL,
$child,
0,
"segment $idx returned empty function data",
keys(%children));
next;
Expand All @@ -6873,10 +6891,13 @@ sub merge
}
} else {
if (!defined($current)) {
lcovutil::report_parallel_error('lcov',
lcovutil::report_parallel_error(
'aggregate',
$ERROR_PARALLEL,
$child,
0,
"segment $idx returned empty trace data",
, keys(%children));
keys(%children));
next;
}
if ($total_trace->merge_tracefile(
Expand All @@ -6889,18 +6910,20 @@ sub merge
}
}; # end eval
if ($@) {
$childstatus = 1 unless $childstatus;
lcovutil::report_parallel_error('lcov', $ERROR_PARALLEL,
$childstatus = 1 << 8 unless $childstatus;
lcovutil::report_parallel_error(
'aggregate',
$ERROR_PARALLEL,
$child,
$childstatus,
"unable to deserialize segment $idx $dumpfile:$@",
keys(%children));
}
}
if (0 != $childstatus) {
lcovutil::report_parallel_error(
'lcov',
$ERROR_CHILD,
"error in child $child processing: non-zero code $childstatus",
keys(%children));
lcovutil::report_parallel_error('aggregate', $ERROR_CHILD,
$child, $childstatus, "while processing segment $idx",
keys(%children));
}
my $end = Time::HiRes::gettimeofday();
$lcovutil::profileData{$idx}{merge} = $end - $start;
Expand Down

0 comments on commit 4bd5094

Please sign in to comment.