summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2010-11-07 10:59:54 +0000
committerPaul Buetow <paul@buetow.org>2010-11-07 10:59:54 +0000
commit7d841dfc79d12aa22578c550ce30bdb234102316 (patch)
tree9ed796a77ac946d8735a08a4f3c1fc0670434365
parent4d10471d2963b090bca90300d133bd1ac74fef81 (diff)
added wait_for_stats help function
-rwxr-xr-xcpuload.pl15
1 files changed, 13 insertions, 2 deletions
diff --git a/cpuload.pl b/cpuload.pl
index efa3196..01a1ec0 100755
--- a/cpuload.pl
+++ b/cpuload.pl
@@ -116,10 +116,20 @@ sub get_load_average (@) {
return %load_average;
}
+sub wait_for_stats () {
+ sleep 1 until %STATS;
+ my $count;
+
+ do {
+ $count = %STATS;
+ sleep 2;
+ } until $count == %STATS;
+}
+
sub graph_stats ($$) {
my ($app, $colors) = @_;
- sleep 1 until %STATS;
+ wait_for_stats;
my $rects = {};
my %prev_stats;
@@ -130,7 +140,8 @@ sub graph_stats ($$) {
# Toggle CPUs
$SIG{USR1} = sub {
%STATS = ();
- sleep 1 until %STATS;
+ wait_for_stats;
+
$width = WIDTH / (keys %STATS) - 1;
$rect_bg->width(WIDTH);