mirror of
https://git.savannah.gnu.org/git/parallel.git
synced 2024-12-23 13:17:54 +00:00
parallel: Experimental bug #37620: alternative instant --load calculation using ps
This commit is contained in:
parent
3b752a668c
commit
635e5081d6
37
src/parallel
37
src/parallel
|
@ -637,7 +637,7 @@ sub get_options_from_array {
|
||||||
sub parse_options {
|
sub parse_options {
|
||||||
# Returns: N/A
|
# Returns: N/A
|
||||||
# Defaults:
|
# Defaults:
|
||||||
$Global::version = 20130222;
|
$Global::version = 20130307;
|
||||||
$Global::progname = 'parallel';
|
$Global::progname = 'parallel';
|
||||||
$Global::infinity = 2**31;
|
$Global::infinity = 2**31;
|
||||||
$Global::debug = 0;
|
$Global::debug = 0;
|
||||||
|
@ -2476,23 +2476,24 @@ sub loadavg {
|
||||||
# last load average computed
|
# last load average computed
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
# Should we update the loadavg file?
|
# Should we update the loadavg file?
|
||||||
my $update_loadavg_file = 0;
|
my $update_loadavg_file = 1;
|
||||||
if(-r $self->{'loadavg_file'}) {
|
if(-r $self->{'loadavg_file'}) {
|
||||||
open(my $uptime_fh, "<", $self->{'loadavg_file'}) || ::die_bug("loadavg_file-r");
|
open(my $load_fh, "<", $self->{'loadavg_file'}) || ::die_bug("loadavg_file-r");
|
||||||
local $/ = undef;
|
local $/ = undef;
|
||||||
my $uptime_out = <$uptime_fh>;
|
my $load_out = <$load_fh>;
|
||||||
close $uptime_fh;
|
close $load_fh;
|
||||||
# load average: 0.76, 1.53, 1.45
|
my $load =()= ($load_out=~/(^[DR]....[^\[])/gm);
|
||||||
if($uptime_out =~ /load averages?: (\d+.\d+)/) {
|
if($load > 0) {
|
||||||
$self->{'loadavg'} = $1;
|
# load is overestimated by 1
|
||||||
::debug("New loadavg: ".$self->{'loadavg'}."\n");
|
$self->{'loadavg'} = $load - 1;
|
||||||
|
::debug("New loadavg: ".$self->{'loadavg'});
|
||||||
} else {
|
} else {
|
||||||
::die_bug("loadavg_invalid_content: $uptime_out");
|
::die_bug("loadavg_invalid_content: $load_out");
|
||||||
}
|
}
|
||||||
::debug("Last update: ".$self->{'last_loadavg_update'});
|
::debug("Last update: ".$self->{'last_loadavg_update'});
|
||||||
if(time - $self->{'last_loadavg_update'} > 10) {
|
if(time - $self->{'last_loadavg_update'} > 1) {
|
||||||
# last loadavg was started 10 seconds ago
|
# last loadavg was started 1 second ago
|
||||||
::debug("Older than 10 sec: ".$self->{'loadavg_file'});
|
::debug("Older than 1 sec: ".$self->{'loadavg_file'});
|
||||||
$update_loadavg_file = 1;
|
$update_loadavg_file = 1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -2505,18 +2506,18 @@ sub loadavg {
|
||||||
$self->{'last_loadavg_update'} = time;
|
$self->{'last_loadavg_update'} = time;
|
||||||
-e $ENV{'HOME'}."/.parallel" or mkdir $ENV{'HOME'}."/.parallel";
|
-e $ENV{'HOME'}."/.parallel" or mkdir $ENV{'HOME'}."/.parallel";
|
||||||
-e $ENV{'HOME'}."/.parallel/tmp" or mkdir $ENV{'HOME'}."/.parallel/tmp";
|
-e $ENV{'HOME'}."/.parallel/tmp" or mkdir $ENV{'HOME'}."/.parallel/tmp";
|
||||||
my $uptime;
|
my $cmd;
|
||||||
if($self->{'string'} eq ":") {
|
if($self->{'string'} eq ":") {
|
||||||
$uptime = "LANG=C uptime";
|
$cmd = "ps ax -o state,command";
|
||||||
} else {
|
} else {
|
||||||
$uptime = $self->sshcommand() . " " . $self->serverlogin() . " LANG=C uptime";
|
$cmd = $self->sshcommand() . " " . $self->serverlogin() .
|
||||||
|
"ps ax -o state,command";
|
||||||
}
|
}
|
||||||
# Run uptime.
|
|
||||||
# As the command can take long to run if run remote
|
# As the command can take long to run if run remote
|
||||||
# save it to a tmp file before moving it to the correct file
|
# save it to a tmp file before moving it to the correct file
|
||||||
my $file = $self->{'loadavg_file'};
|
my $file = $self->{'loadavg_file'};
|
||||||
my ($dummy_fh, $tmpfile) = ::tempfile(SUFFIX => ".loa");
|
my ($dummy_fh, $tmpfile) = ::tempfile(SUFFIX => ".loa");
|
||||||
qx{ ($uptime > $tmpfile && mv $tmpfile $file) & };
|
qx{ ($cmd > $tmpfile && mv $tmpfile $file) & };
|
||||||
}
|
}
|
||||||
return $self->{'loadavg'};
|
return $self->{'loadavg'};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue