From cfec4e811b14dfebdb6883c8c743d170fcfc40d5 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sun, 7 Nov 2010 11:09:21 +0000 Subject: added draw_background --- cpuload.pl | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) (limited to 'cpuload.pl') diff --git a/cpuload.pl b/cpuload.pl index 01a1ec0..ef45c35 100755 --- a/cpuload.pl +++ b/cpuload.pl @@ -118,12 +118,15 @@ sub get_load_average (@) { sub wait_for_stats () { sleep 1 until %STATS; - my $count; +} + +sub draw_background ($$$) { + my ($app, $colors, $rect) = @_; - do { - $count = %STATS; - sleep 2; - } until $count == %STATS; + $rect->width(WIDTH); + $rect->height(HEIGHT); + $app->fill($rect, $colors->{black}); + $app->update($rect); } sub graph_stats ($$) { @@ -131,31 +134,32 @@ sub graph_stats ($$) { wait_for_stats; + my $num_stats = keys %STATS; + my $width = WIDTH / $num_stats - 1; + my $rects = {}; my %prev_stats; my %last_loads; - my $width = WIDTH / (keys %STATS) - 1; my $rect_bg = SDL::Rect->new(); # Toggle CPUs $SIG{USR1} = sub { %STATS = (); wait_for_stats; - - $width = WIDTH / (keys %STATS) - 1; - - $rect_bg->width(WIDTH); - $rect_bg->height(HEIGHT); - $app->fill($rect_bg, $colors->{black}); - $app->update($rect_bg); - - %prev_stats = (); - %last_loads = (); }; loop { my ($x, $y) = (0, 0); + my $new_num_stats = keys %STATS; + if ($new_num_stats != $num_stats) { + %prev_stats = (); + %last_loads = (); + $num_stats = $new_num_stats; + $width = WIDTH / $num_stats - 1; + draw_background $app, $colors, $rect_bg; + } + for my $key (sort keys %STATS) { my ($host, $name) = split ';', $key; my %stat = map { my ($k, $v) = split '='; $k => $v } split ';', $STATS{$key}; -- cgit v1.2.3