mirror of
https://git.savannah.gnu.org/git/parallel.git
synced 2024-12-23 05:07:54 +00:00
niceload: test + bugfix for --sensor
This commit is contained in:
parent
111c7384f7
commit
59a1d67b59
15
src/niceload
15
src/niceload
|
@ -602,6 +602,7 @@ sub nonblockGetLines {
|
||||||
|
|
||||||
sub read_sensor {
|
sub read_sensor {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
::debug("read_sensor");
|
||||||
my $fh = $self->{'sensor_fh'};
|
my $fh = $self->{'sensor_fh'};
|
||||||
if(not $fh) {
|
if(not $fh) {
|
||||||
# Start the sensor
|
# Start the sensor
|
||||||
|
@ -612,13 +613,18 @@ sub read_sensor {
|
||||||
my ($eof,@lines) = nonblockGetLines($fh);
|
my ($eof,@lines) = nonblockGetLines($fh);
|
||||||
|
|
||||||
# new load = last full line
|
# new load = last full line
|
||||||
foreach my $line ( @lines ) {
|
foreach my $line (@lines) {
|
||||||
if(defined $line) {
|
if(defined $line) {
|
||||||
print "Pipe saw: $eof [$line]\n";
|
::debug("Pipe saw: $eof [$line]\n");
|
||||||
$Global::last_sensor_reading = $line;
|
$Global::last_sensor_reading = $line;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if($eof) { undef($self->{'sensor_fh'}); }
|
if($eof) {
|
||||||
|
# End of file => Restart the sensor
|
||||||
|
close $fh;
|
||||||
|
open($fh, "-|", $::opt_sensor) || ::die_bug("Cannot open: $::opt_sensor");
|
||||||
|
$self->{'sensor_fh'} = $fh;
|
||||||
|
}
|
||||||
|
|
||||||
return $Global::last_sensor_reading;
|
return $Global::last_sensor_reading;
|
||||||
}
|
}
|
||||||
|
@ -627,6 +633,7 @@ sub load_status {
|
||||||
# Returns:
|
# Returns:
|
||||||
# loadavg or sensor measurement
|
# loadavg or sensor measurement
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
|
||||||
if($::opt_sensor) {
|
if($::opt_sensor) {
|
||||||
if(not defined $self->{'load_status'} or
|
if(not defined $self->{'load_status'} or
|
||||||
$self->{'load_status_cache_time'} + $self->{'recheck'} < time) {
|
$self->{'load_status_cache_time'} + $self->{'recheck'} < time) {
|
||||||
|
@ -635,7 +642,7 @@ sub load_status {
|
||||||
sleep 1;
|
sleep 1;
|
||||||
$self->{'load_status'} = $self->read_sensor();
|
$self->{'load_status'} = $self->read_sensor();
|
||||||
}
|
}
|
||||||
$self->{'load_status_cache_time'} = time;
|
$self->{'load_status_cache_time'} = time - 0.001;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
# Normal load avg
|
# Normal load avg
|
||||||
|
|
|
@ -9,5 +9,11 @@ while uptime | grep -v age:.[1-9][0-9].[0-9][0-9] >/dev/null ; do (timeout 5 nic
|
||||||
|
|
||||||
echo '### Test -p'
|
echo '### Test -p'
|
||||||
perl -e '$|=1;while($t++<3){sleep(1);print "."}' &
|
perl -e '$|=1;while($t++<3){sleep(1);print "."}' &
|
||||||
# The above should be suspended for at least 4 seconds
|
# The above will normally take 3.6 sec
|
||||||
stdout /usr/bin/time -f %e niceload -D -l 9 -p $! | perl -ne '$_ > 6 and print "OK\n"'
|
# It should be suspended so it at least takes 5 seconds
|
||||||
|
stdout /usr/bin/time -f %e niceload -l 8 -p $! | perl -ne '$_ >= 5 and print "OK\n"'
|
||||||
|
|
||||||
|
echo "### Test --sensor -l negative"
|
||||||
|
timeout 10 nice nice dd iflag=fullblock if=/dev/zero of=/dev/null bs=10G &
|
||||||
|
niceload -t 1 --sensor 'free | field 3 | head -3|tail -1' -l -5000000 "free -g;echo more than 5 GB used"
|
||||||
|
|
||||||
|
|
|
@ -3,3 +3,9 @@
|
||||||
0 eq 0
|
0 eq 0
|
||||||
### Test -p
|
### Test -p
|
||||||
...OK
|
...OK
|
||||||
|
### Test --sensor -l negative
|
||||||
|
total used free shared buffers cached
|
||||||
|
Mem: 7 6 1 0 0 0
|
||||||
|
-/+ buffers/cache: 6 1
|
||||||
|
Swap: 9 2 7
|
||||||
|
more than 5 GB used
|
||||||
|
|
Loading…
Reference in a new issue