"Fossies" - the Fresh Open Source Software Archive

Member "xosview-1.23/hpux/loadmeter.cc" (11 Jul 2020, 2174 Bytes) of package /linux/misc/xosview-1.23.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "loadmeter.cc" see the Fossies "Dox" file reference documentation.

    1 //  
    2 //  Copyright (c) 1994, 1995, 1997 by Mike Romberg ( romberg@fsl.noaa.gov )
    3 //
    4 //  This file may be distributed under terms of the GPL
    5 //
    6 
    7 #include "loadmeter.h"
    8 #include "xosview.h"
    9 #include <stdlib.h>
   10 #include <sys/pstat.h>
   11 
   12 LoadMeter::LoadMeter( XOSView *parent )
   13   : FieldMeterDecay( parent, 2, "LOAD", "PROCS/MIN", 1, 0 ){
   14 }
   15 
   16 LoadMeter::~LoadMeter( void ){
   17 }
   18 
   19 void LoadMeter::checkResources( void ){
   20   FieldMeterDecay::checkResources();
   21 
   22   warnloadcol_ = parent_->allocColor(parent_->getResource( "loadWarnColor" ));
   23   procloadcol_ = parent_->allocColor(parent_->getResource( "loadProcColor" ));
   24 
   25   setfieldcolor( 0, procloadcol_ );
   26   setfieldcolor( 1, parent_->getResource( "loadIdleColor" ) );
   27   priority_ = atoi (parent_->getResource( "loadPriority" ) );
   28   dodecay_ = parent_->isResourceTrue( "loadDecay" );
   29   SetUsedFormat( parent_->getResource( "loadUsedFormat" ));
   30 
   31   alarmThreshold = atoi (parent_->getResource("loadAlarmThreshold"));
   32 
   33   if (dodecay_){
   34     //  Warning:  Since the loadmeter changes scale occasionally, old
   35     //  decay values need to be rescaled.  However, if they are rescaled,
   36     //  they could go off the edge of the screen.  Thus, for now, to
   37     //  prevent this whole problem, the load meter can not be a decay
   38     //  meter.  The load is a decaying average kind of thing anyway,
   39     //  so having a decaying load average is redundant.
   40          std::cerr << "Warning:  The loadmeter can not be configured as a decay\n"
   41          << "  meter.  See the source code (" << __FILE__ << ") for further\n"
   42          << "  details.\n";
   43     dodecay_ = 0;
   44   }
   45 }
   46 
   47 void LoadMeter::checkevent( void ){
   48   getloadinfo();
   49 
   50   drawfields();
   51 }
   52 
   53 
   54 void LoadMeter::getloadinfo( void ){
   55 
   56   struct pst_dynamic pstd; 
   57 
   58   pstat_getdynamic(&pstd, sizeof(pstd), 1, 0);
   59 
   60   fields_[0] = pstd.psd_avg_1_min;
   61 
   62   if ( fields_[0] > alarmThreshold ) {
   63     if (total_ == alarmThreshold ) {
   64       setfieldcolor( 0, warnloadcol_ );
   65       drawlegend();
   66     }
   67     total_ = fields_[1] = 20;
   68   } else {
   69     if (total_ == 20 ) {
   70       setfieldcolor( 0, procloadcol_ );
   71       drawlegend();
   72     }
   73     total_ = fields_[1] = alarmThreshold;
   74   }
   75 
   76   setUsed( fields_[0], total_ );
   77 }