From 578434adcdc2a1c516983657dbd103101ed2f93a Mon Sep 17 00:00:00 2001 From: "pbuetow (lap824)" Date: Sun, 22 Jan 2012 12:43:20 +0100 Subject: fix is_host_summary stuff --- loadbars | 59 ++++++++++++++++++++--------------------------------------- 1 file changed, 20 insertions(+), 39 deletions(-) diff --git a/loadbars b/loadbars index fab685f..d331484 100755 --- a/loadbars +++ b/loadbars @@ -261,6 +261,7 @@ sub main_loop ($@) { SDL::Font->new('font.png')->use(); my $num_stats = keys %CPUSTATS; + $num_stats += keys %MEMSTATS_HAS if $C{showmem}; my $rects = {}; my %prev_stats; @@ -364,7 +365,6 @@ sub main_loop ($@) { do { my ( $x, $y ) = ( 0, 0 ); - my %is_host_summary; my $new_num_stats = keys %CPUSTATS; $new_num_stats += keys %MEMSTATS_HAS if $C{showmem}; @@ -423,7 +423,7 @@ sub main_loop ($@) { : 1 } keys %$cpuaverage; - my $is_host_summary = exists $is_host_summary{$host}; + my $is_host_summary = $name eq 'cpu' ? 1 : 0; my $rect_separator = undef; @@ -441,10 +441,8 @@ sub main_loop ($@) { my $add_x = 0; my ($rect_memused, $rect_memfree, $rect_buffers, $rect_cached, $rect_swapused, $rect_swapfree); - if ( $is_host_summary && $C{showmem}) { - } - unless ( $is_host_summary || !$C{showcores} ) { + if ( $is_host_summary && $C{showcores} ) { $current_corenum = 0; $rect_separator = get_rect $rects, "$key;separator"; $rect_separator->width(1); @@ -454,6 +452,10 @@ sub main_loop ($@) { $app->fill( $rect_separator, Loadbars::GREY ); } + if ($C{showmem} && $name eq 'cpu') { + $add_x = $width + 1, + } + $y = $C{height} - $heights{system}; $rect_system->width($width); $rect_system->height( $heights{system} ); @@ -530,42 +532,24 @@ sub main_loop ($@) { $rect_peak->width($width); $rect_peak->height(1); $rect_peak->x($x); - $rect_peak->y( - $C{height} - $maxheights{system} - $maxheights{user} ); - - $max_all = - sum @{$cpumax} - {qw(user system iowait irq softirq steal guest)}; - - $app->fill( - $rect_peak, - $max_all > Loadbars::USER_ORANGE ? Loadbars::ORANGE - : ( - $max_all > Loadbars::USER_YELLOW0 ? Loadbars::YELLOW0 - : (Loadbars::YELLOW) - ) - ); + $rect_peak->y( $C{height} - $maxheights{system} - $maxheights{user} ); + + $max_all = sum @{$cpumax} {qw(user system iowait irq softirq steal guest)}; + + $app->fill( $rect_peak, $max_all > Loadbars::USER_ORANGE ? Loadbars::ORANGE + : ( $max_all > Loadbars::USER_YELLOW0 ? Loadbars::YELLOW0 : (Loadbars::YELLOW))); } - $app->fill( - $rect_user, - $all > Loadbars::USER_ORANGE ? Loadbars::ORANGE - : ( - $all > Loadbars::USER_YELLOW0 ? Loadbars::YELLOW0 - : (Loadbars::YELLOW) - ) - ); - $app->fill( $rect_system, - $cpuaverage->{system} > Loadbars::SYSTEM_BLUE0 - ? Loadbars::BLUE0 - : Loadbars::BLUE ); + $app->fill( $rect_user, $all > Loadbars::USER_ORANGE ? Loadbars::ORANGE + : ( $all > Loadbars::USER_YELLOW0 ? Loadbars::YELLOW0 : (Loadbars::YELLOW))); + $app->fill( $rect_system, $cpuaverage->{system} > Loadbars::SYSTEM_BLUE0 + ? Loadbars::BLUE0 : Loadbars::BLUE ); my ( $y, $space ) = ( 5, $font_height ); my @loadavg = split ';', $AVGSTATS{$host}; - $is_host_summary{$host} = 1 if defined $loadavg[0]; if ( $C{displaytxt} ) { - if ( $C{displaytxthost} && not $is_host_summary ) { + if ( $C{displaytxthost} && $is_host_summary ) { # If hostname is printed don't use FQDN # because of its length. @@ -574,10 +558,7 @@ sub main_loop ($@) { } else { - $app->print( $x, $y, sprintf '%i:', - $C{showcores} - ? $current_corenum - : $current_barnum + 1 ); + $app->print( $x, $y, sprintf '%i:', $C{showcores} ? $current_corenum : $current_barnum + 1 ); } if ( $C{extended} ) { @@ -598,7 +579,7 @@ sub main_loop ($@) { $app->print( $x, $y += $space, sprintf '%02d%s', norm $max_all, 'pk') if $C{extended}; - unless ($is_host_summary) { + if ($is_host_summary) { if ( defined $loadavg[0] ) { $app->print( $x, $y += $space, 'avg:' ); $app->print( $x, $y += $space, sprintf "%.2f", $loadavg[0]); -- cgit v1.2.3