mirror of
https://git.proxmox.com/git/pve-common
synced 2025-07-27 10:01:38 +00:00
run_command: improve performance for logging and long lines
to call out/err/logfunc with each line, we search for a newline and call outfunc/logfunc with everything before that since we do a select/read (with 4096 size) in a loop, this means that if we have very long lines, we search for a newline in an ever growing buffer (for which we know does not contain a newline) so instead, only search the new data for newlines Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
parent
8fb28ab914
commit
cb9db10c1a
@ -497,12 +497,13 @@ sub run_command {
|
|||||||
if ($h eq $reader) {
|
if ($h eq $reader) {
|
||||||
if ($outfunc || $logfunc) {
|
if ($outfunc || $logfunc) {
|
||||||
eval {
|
eval {
|
||||||
$outlog .= $buf;
|
while ($buf =~ s/^([^\010\r\n]*)(\r|\n|(\010)+|\r\n)//) {
|
||||||
while ($outlog =~ s/^([^\010\r\n]*)(\r|\n|(\010)+|\r\n)//s) {
|
my $line = $outlog . $1;
|
||||||
my $line = $1;
|
$outlog = '';
|
||||||
&$outfunc($line) if $outfunc;
|
&$outfunc($line) if $outfunc;
|
||||||
&$logfunc($line) if $logfunc;
|
&$logfunc($line) if $logfunc;
|
||||||
}
|
}
|
||||||
|
$outlog .= $buf;
|
||||||
};
|
};
|
||||||
my $err = $@;
|
my $err = $@;
|
||||||
if ($err) {
|
if ($err) {
|
||||||
@ -517,12 +518,13 @@ sub run_command {
|
|||||||
} elsif ($h eq $error) {
|
} elsif ($h eq $error) {
|
||||||
if ($errfunc || $logfunc) {
|
if ($errfunc || $logfunc) {
|
||||||
eval {
|
eval {
|
||||||
$errlog .= $buf;
|
while ($buf =~ s/^([^\010\r\n]*)(\r|\n|(\010)+|\r\n)//s) {
|
||||||
while ($errlog =~ s/^([^\010\r\n]*)(\r|\n|(\010)+|\r\n)//s) {
|
my $line = $errlog . $1;
|
||||||
my $line = $1;
|
$errlog = '';
|
||||||
&$errfunc($line) if $errfunc;
|
&$errfunc($line) if $errfunc;
|
||||||
&$logfunc($line) if $logfunc;
|
&$logfunc($line) if $logfunc;
|
||||||
}
|
}
|
||||||
|
$errlog .= $buf;
|
||||||
};
|
};
|
||||||
my $err = $@;
|
my $err = $@;
|
||||||
if ($err) {
|
if ($err) {
|
||||||
|
Loading…
Reference in New Issue
Block a user