parallel: --files/--results --line-buffer fix.

This commit is contained in:
Ole Tange 2016-09-22 23:54:38 +02:00
parent 5829f512c1
commit a4ddcbf8bc

View file

@ -8107,11 +8107,11 @@ sub print {
next; next;
} }
::debug("print", "File descriptor $fdno (", $self->fh($fdno,"name"), "):\n"); ::debug("print", "File descriptor $fdno (", $self->fh($fdno,"name"), "):\n");
if($opt::files) { if($opt::linebuffer) {
$self->files_print($fdno,$in_fh,$out_fd);
} elsif($opt::linebuffer) {
# Line buffered print out # Line buffered print out
$self->linebuffer_print($fdno,$in_fh,$out_fd); $self->linebuffer_print($fdno,$in_fh,$out_fd);
} elsif($opt::files) {
$self->files_print($fdno,$in_fh,$out_fd);
} elsif($opt::tag or defined $opt::tagstring) { } elsif($opt::tag or defined $opt::tagstring) {
$self->tag_print($fdno,$in_fh,$out_fd); $self->tag_print($fdno,$in_fh,$out_fd);
} else { } else {
@ -8137,19 +8137,17 @@ sub files_print {
my $self = shift; my $self = shift;
my ($fdno,$in_fh,$out_fd) = @_; my ($fdno,$in_fh,$out_fd) = @_;
if($opt::group and defined $self->{'exitstatus'}) { # If the job is dead: close printing fh. Needed for --compress
# If the job is dead: close printing fh. Needed for --compress close $self->fh($fdno,"w");
close $self->fh($fdno,"w"); if($? and $opt::compress) {
if($? and $opt::compress) { ::error($opt::compress_program." failed.");
::error($opt::compress_program." failed."); $self->set_exitstatus(255);
$self->set_exitstatus(255);
}
if($opt::compress) {
# Kill the decompressor which will not be needed
CORE::kill "TERM", $self->fh($fdno,"rpid");
}
close $in_fh;
} }
if($opt::compress) {
# Kill the decompressor which will not be needed
CORE::kill "TERM", $self->fh($fdno,"rpid");
}
close $in_fh;
if($opt::pipe and $self->virgin()) { if($opt::pipe and $self->virgin()) {
# Nothing was printed to this job: # Nothing was printed to this job:
@ -8189,46 +8187,57 @@ sub linebuffer_print {
} }
} }
} }
# This seek will clear EOF if($opt::files or $opt::results) {
seek $in_fh, tell($in_fh), 0; if($fdno == 1 and not $self->fh($fdno,"printed")) {
# The read is non-blocking: The $in_fh is set to non-blocking. print $out_fd $self->tag(),$self->fh($fdno,"name"),"\n";
# 32768 --tag = 5.1s $self->set_fh($fdno,"printed",1);
# 327680 --tag = 4.4s }
# 1024000 --tag = 4.4s } else {
# 3276800 --tag = 4.3s # This seek will clear EOF
# 10240000 --tag = 4.3s seek $in_fh, tell($in_fh), 0;
# 32768000 --tag = 4.7s my $outputlength = 0;
my $outputlength = 0; # The read is non-blocking: The $in_fh is set to non-blocking.
while(read($in_fh,substr($$partial,length $$partial),3276800)) { # 32768 --tag = 5.1s
# Append to $$partial # 327680 --tag = 4.4s
# Find the last \n or \r # 1024000 --tag = 4.4s
my $i = (::rindex64($partial,"\n")+1) || (::rindex64($partial,"\r")+1); # 3276800 --tag = 4.3s
if($i) { # 10240000 --tag = 4.3s
# One or more complete lines were found # 32768000 --tag = 4.7s
$outputlength += $i; while(read($in_fh,substr($$partial,length $$partial),3276800)) {
if($opt::tag or defined $opt::tagstring) { # Append to $$partial
# Replace ^ with $tag within the full line # Find the last \n or \r
my $tag = $self->tag(); my $i = (::rindex64($partial,"\n")+1) || (::rindex64($partial,"\r")+1);
substr($$partial,0,$i) =~ s/^/$tag/gm; if($i) {
# Length of partial line has changed: Find the last \n/\r again # One or more complete lines were found
$i = (::rindex64($partial,"\n")+1) || (::rindex64($partial,"\r")+1); $outputlength += $i;
if($opt::tag or defined $opt::tagstring) {
# Replace ^ with $tag within the full line
my $tag = $self->tag();
substr($$partial,0,$i) =~ s/^/$tag/gm;
# Length of partial line has changed: Find the last \n/\r again
$i = (::rindex64($partial,"\n")+1) || (::rindex64($partial,"\r")+1);
}
# Print up to and including the last \n
print $out_fd substr($$partial,0,$i);
# Remove the printed part
substr($$partial,0,$i) = "";
} }
# Print up to and including the last \n
print $out_fd substr($$partial,0,$i);
# Remove the printed part
substr($$partial,0,$i) = "";
} }
$self->add_returnsize($outputlength);
} }
$self->add_returnsize($outputlength);
if(defined $self->{'exitstatus'}) { if(defined $self->{'exitstatus'}) {
# If the job is dead: print the remaining partial line if($opt::files or $opt::results) {
# read remaining $self->add_returnsize(-s $self->fh($fdno,"name"));
$self->add_returnsize(length $$partial); } else {
if($$partial and ($opt::tag or defined $opt::tagstring)) { # If the job is dead: print the remaining partial line
my $tag = $self->tag(); # read remaining
$$partial =~ s/^/$tag/gm; $self->add_returnsize(length $$partial);
if(length $$partial and ($opt::tag or defined $opt::tagstring)) {
my $tag = $self->tag();
$$partial =~ s/^/$tag/gm;
}
print $out_fd $$partial;
} }
print $out_fd $$partial;
# Release the memory # Release the memory
undef $$partial; undef $$partial;
if($self->fh($fdno,"rpid") and CORE::kill 0, $self->fh($fdno,"rpid")) { if($self->fh($fdno,"rpid") and CORE::kill 0, $self->fh($fdno,"rpid")) {