parallel: implemented --tag

This commit is contained in:
Ole Tange 2011-09-24 02:16:06 +02:00
parent d0f6c9a0aa
commit 9fad573774
4 changed files with 58 additions and 5 deletions

View file

@ -398,6 +398,7 @@ sub options_hash {
"shellquote|shell_quote|shell-quote" => \$::opt_shellquote, "shellquote|shell_quote|shell-quote" => \$::opt_shellquote,
"nice=i" => \$::opt_nice, "nice=i" => \$::opt_nice,
"timeout=i" => \$::opt_timeout, "timeout=i" => \$::opt_timeout,
"tag" => \$::opt_tag,
"onall" => \$::opt_onall, "onall" => \$::opt_onall,
"nonall" => \$::opt_nonall, "nonall" => \$::opt_nonall,
"sshlogin|S=s" => \@::opt_sshlogin, "sshlogin|S=s" => \@::opt_sshlogin,
@ -1678,6 +1679,11 @@ sub usage {
"--recstart str Record start separator for --pipe.", "--recstart str Record start separator for --pipe.",
"", "",
"See 'man $Global::progname' for details", "See 'man $Global::progname' for details",
"",
"When using GNU Parallel for a publication please cite:",
"",
"O. Tange (2011): GNU Parallel - The Command-Line Power Tool,",
";login: The USENIX Magazine, February 2011:42-47.",
""); "");
} }
@ -3461,22 +3467,37 @@ sub print {
if($Global::debug) { if($Global::debug) {
print STDERR "ERR:\n"; print STDERR "ERR:\n";
} }
if($::opt_tag) {
my $tag = $self->{'commandline'}->args_as_string();
while(<$err>) {
print STDERR $tag,"\t",$_;
}
} else {
my $buf; my $buf;
while(sysread($err,$buf,1000_000)) { while(sysread($err,$buf,1000_000)) {
print STDERR $buf; print STDERR $buf;
} }
}
flush STDERR; flush STDERR;
if($::opt_files) { if($::opt_files) {
print STDOUT $self->{'stdoutfilename'},"\n"; print STDOUT $self->{'stdoutfilename'},"\n";
} else { } else {
my $buf;
seek $out, 0, 0; seek $out, 0, 0;
if($Global::debug) { if($Global::debug) {
print STDOUT "OUT:\n"; print STDOUT "OUT:\n";
} }
if($::opt_tag) {
my $tag = $self->{'commandline'}->args_as_string();
while(<$out>) {
print STDOUT $tag,"\t",$_;
}
} else {
while(sysread($out,$buf,1000_000)) { while(sysread($out,$buf,1000_000)) {
print STDOUT $buf; print STDOUT $buf;
} }
}
flush STDOUT; flush STDOUT;
::debug("<<joboutput $command\n"); ::debug("<<joboutput $command\n");
} }
@ -3691,6 +3712,14 @@ sub number_of_args {
return $#{$self->{'arg_list'}}+1; return $#{$self->{'arg_list'}}+1;
} }
sub args_as_string {
# Returns:
# all unmodified arguments joined with ' ' (similar to {})
my $self = shift;
return (join " ", map { $_->orig() }
map { @$_ } @{$self->{'arg_list'}});
}
sub len { sub len {
# The length of the command line with args substituted # The length of the command line with args substituted
my $self = shift; my $self = shift;

View file

@ -1148,6 +1148,12 @@ and it will open a tty for the job. When the job is done, the next job
will get the tty. will get the tty.
=item B<--tag>
Tag lines with arguments. Each output line will be prepended with the
arguments and TAB (\t).
=item B<--tmpdir> I<dirname> =item B<--tmpdir> I<dirname>
Directory for temporary files. GNU B<parallel> normally buffers output Directory for temporary files. GNU B<parallel> normally buffers output

View file

@ -12,4 +12,11 @@ echo '### Test --use-cpus-instead-of-cores'
echo 'Cores should complete first on machines with less than 4 physical CPUs' echo 'Cores should complete first on machines with less than 4 physical CPUs'
wait wait
echo '### Test --tag ::: a ::: b'
stdout parallel -k --tag -j1 echo stderr-{.} ">&2;" echo stdout-{} ::: a ::: b
echo '### Test --tag ::: a b'
stdout parallel -k --tag -j1 echo stderr-{.} ">&2;" echo stdout-{} ::: a b
echo '### Test --tag -X ::: a b'
stdout parallel -k --tag -X -j1 echo stderr-{.} ">&2;" echo stdout-{} ::: a b

View file

@ -6,3 +6,14 @@
Cores should complete first on machines with less than 4 physical CPUs Cores should complete first on machines with less than 4 physical CPUs
cores done cores done
CPUs done CPUs done
### Test --tag ::: a ::: b
a b stderr-a b
a b stdout-a b
### Test --tag ::: a b
a stderr-a
a stdout-a
b stderr-b
b stdout-b
### Test --tag -X ::: a b
a b stderr-a stderr-b
a b stdout-a stdout-b