"Fossies" - the Fresh Open Source Software Archive

Member "xosview-1.23/irix65/gfxmeter.cc" (11 Jul 2020, 3410 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 "gfxmeter.cc" see the Fossies "Dox" file reference documentation.

    1 //  
    2 //  Initial port performed by Stefan Eilemann (eilemann@gmail.com)
    3 //
    4 
    5 #include "gfxmeter.h"
    6 #include "xosview.h"
    7 
    8 #include <stdlib.h>
    9 #include <unistd.h>
   10 #include <invent.h>
   11 #include <iostream>
   12 
   13 using namespace std;
   14 
   15 // GfxMeter display swapbuffers per second. max is base rate for one gfx pipe.
   16 
   17 GfxMeter::GfxMeter(XOSView *parent, int max)
   18         : FieldMeterGraph(parent, 2, "GFX","SWAPBUF/S", 1, 1, 0 )
   19 {
   20     lastalarmstate = -1;
   21     total_ = 0;
   22     _nPipes = nPipes();
   23     total_ = _nPipes * max;
   24 
   25     if ( total_==0 ) {
   26         parent_->done(1);
   27         return;
   28     }
   29 }
   30 
   31 GfxMeter::~GfxMeter(void)
   32 {
   33 }
   34 
   35 int GfxMeter::nPipes(void)
   36 {
   37     int _nPipes = 0;
   38 
   39     setinvent();
   40     for( inventory_t *inv = getinvent(); inv != NULL; inv = getinvent() )
   41     {
   42         if ( inv->inv_class==INV_GRAPHICS )
   43         {
   44             _nPipes++;
   45         }
   46     }
   47     return _nPipes;
   48 }
   49 
   50 void GfxMeter::checkResources(void)
   51 {
   52     FieldMeterGraph::checkResources();
   53 
   54     swapgfxcol_ = parent_->allocColor(parent_->getResource( "gfxSwapColor" ));
   55     warngfxcol_ = parent_->allocColor(parent_->getResource( "gfxWarnColor" ));
   56     critgfxcol_ = parent_->allocColor(parent_->getResource( "gfxCritColor" ));
   57 
   58     setfieldcolor(0, parent_->getResource( "gfxSwapColor" ));
   59     setfieldcolor(1, parent_->getResource("gfxIdleColor"));
   60     priority_ = atoi (parent_->getResource("gfxPriority"));
   61     useGraph_ = parent_->isResourceTrue("gfxGraph");
   62     dodecay_ = parent_->isResourceTrue( "gfxDecay" );
   63     SetUsedFormat(parent_->getResource("gfxUsedFormat"));
   64 
   65     warnThreshold = atoi (parent_->getResource("gfxWarnThreshold")) * _nPipes;
   66     critThreshold = atoi (parent_->getResource("gfxCritThreshold")) * _nPipes;
   67 
   68     if (dodecay_){
   69         //  Warning:  Since the gfxmeter changes scale occasionally, old
   70         //  decay values need to be rescaled.  However, if they are rescaled,
   71         //  they could go off the edge of the screen.  Thus, for now, to
   72         //  prevent this whole problem, the gfx meter can not be a decay
   73         //  meter.  The gfx is a decaying average kind of thing anyway,
   74         //  so having a decaying gfx average is redundant.
   75            std::cerr << "Warning:  The gfxmeter can not be configured as a decay\n"
   76              << "  meter. See the source code (" <<__FILE__<< ") for further\n"
   77              << "  details.\n";
   78         dodecay_ = 0;
   79     }
   80 }
   81 
   82 void GfxMeter::checkevent(void)
   83 {
   84     getgfxinfo();
   85     drawfields();
   86 }
   87 
   88 void GfxMeter::getgfxinfo(void)
   89 {
   90     SarMeter::GfxInfo *gi = SarMeter::Instance()->getGfxInfo();
   91 
   92     fields_[0] = (float)gi->swapBuf;
   93     
   94     if ( fields_[0] < warnThreshold ) 
   95         alarmstate = 0;
   96     else
   97         if ( fields_[0] >= critThreshold )
   98             alarmstate = 2;
   99         else
  100             alarmstate = 1;
  101   
  102     if ( alarmstate != lastalarmstate )
  103     {
  104         if ( alarmstate == 0 )
  105             setfieldcolor( 0, swapgfxcol_ );
  106         else
  107             if ( alarmstate == 1 )
  108                 setfieldcolor( 0, warngfxcol_ );
  109             else
  110                 setfieldcolor( 0, critgfxcol_ );
  111     drawlegend();
  112         lastalarmstate = alarmstate;
  113     }
  114   
  115     if ( fields_[0]*5.0<total_ )
  116         total_ = fields_[0];
  117     else
  118         if ( fields_[0]>total_ )
  119             total_ = fields_[0]*5.0;
  120       
  121     if ( total_ < 1.0)
  122         total_ = 1.0;
  123     
  124     fields_[1] = (float) (total_ - fields_[0]);
  125 
  126     setUsed(fields_[0], (float) 1.0);
  127 }