niceload: test + bugfix for --sensor

This commit is contained in:
Ole Tange 2012-12-03 00:02:51 +01:00
parent 111c7384f7
commit 59a1d67b59
3 changed files with 25 additions and 6 deletions

View file

@ -602,6 +602,7 @@ sub nonblockGetLines {
sub read_sensor {
my $self = shift;
::debug("read_sensor");
my $fh = $self->{'sensor_fh'};
if(not $fh) {
# Start the sensor
@ -614,11 +615,16 @@ sub read_sensor {
# new load = last full line
foreach my $line (@lines) {
if(defined $line) {
print "Pipe saw: $eof [$line]\n";
::debug("Pipe saw: $eof [$line]\n");
$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;
}
@ -627,6 +633,7 @@ sub load_status {
# Returns:
# loadavg or sensor measurement
my $self = shift;
if($::opt_sensor) {
if(not defined $self->{'load_status'} or
$self->{'load_status_cache_time'} + $self->{'recheck'} < time) {
@ -635,7 +642,7 @@ sub load_status {
sleep 1;
$self->{'load_status'} = $self->read_sensor();
}
$self->{'load_status_cache_time'} = time;
$self->{'load_status_cache_time'} = time - 0.001;
}
} else {
# Normal load avg

View file

@ -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'
perl -e '$|=1;while($t++<3){sleep(1);print "."}' &
# The above should be suspended for at least 4 seconds
stdout /usr/bin/time -f %e niceload -D -l 9 -p $! | perl -ne '$_ > 6 and print "OK\n"'
# The above will normally take 3.6 sec
# 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"

View file

@ -3,3 +3,9 @@
0 eq 0
### Test -p
...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