"Fossies" - the Fresh Open Source Software Archive

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

    1 //  
    2 //  Initial port performed by Greg Onufer (exodus@cheers.bungi.com)
    3 //
    4 
    5 #include "pagemeter.h"
    6 #include <stdlib.h>
    7 #include <sys/sysinfo.h>
    8 
    9 
   10 PageMeter::PageMeter(XOSView *parent, kstat_ctl_t *_kc, float max)
   11     : FieldMeterGraph( parent, 3, "PAGE", "IN/OUT/IDLE")
   12 {
   13     kc = _kc;
   14 
   15     for (int i = 0 ; i < 2 ; i++)
   16         for (int j = 0 ; j < 2 ; j++)
   17             pageinfo_[j][i] = 0;
   18 
   19     maxspeed_ = max;
   20     pageindex_ = 0;
   21     cpustats = KStatList::getList(kc, KStatList::CPU_STAT);
   22 }
   23 
   24 PageMeter::~PageMeter(void)
   25 {
   26 }
   27 
   28 void PageMeter::checkResources(void)
   29 {
   30     FieldMeterGraph::checkResources();
   31 
   32     setfieldcolor(0, parent_->getResource("pageInColor"));
   33     setfieldcolor(1, parent_->getResource("pageOutColor"));
   34     setfieldcolor(2, parent_->getResource("pageIdleColor"));
   35     priority_ = atoi(parent_->getResource("pagePriority"));
   36     maxspeed_ *= priority_ / 10.0;
   37     dodecay_ = parent_->isResourceTrue("pageDecay");
   38     useGraph_ = parent_->isResourceTrue("pageGraph");
   39     SetUsedFormat(parent_->getResource("pageUsedFormat"));
   40 }
   41 
   42 void PageMeter::checkevent(void)
   43 {
   44     getpageinfo();
   45     drawfields();
   46 }
   47 
   48 void PageMeter::getpageinfo(void)
   49 {
   50     cpu_stat_t cs;
   51     total_ = 0;
   52     pageinfo_[pageindex_][0] = 0; // pgin
   53     pageinfo_[pageindex_][1] = 0; // pgout
   54     cpustats->update(kc);
   55 
   56     for (unsigned int i = 0; i < cpustats->count(); i++) {
   57         if (kstat_read(kc, (*cpustats)[i], &cs) == -1)
   58             continue;
   59         pageinfo_[pageindex_][0] += cs.cpu_vminfo.pgpgin;
   60         pageinfo_[pageindex_][1] += cs.cpu_vminfo.pgpgout;
   61     }
   62 
   63     int oldindex = (pageindex_ + 1) % 2;
   64     for (int i = 0; i < 2; i++) {
   65         if (pageinfo_[oldindex][i] == 0)
   66             pageinfo_[oldindex][i] = pageinfo_[pageindex_][i];
   67 
   68         fields_[i] = pageinfo_[pageindex_][i] - pageinfo_[oldindex][i];
   69         total_ += fields_[i];
   70     }
   71 
   72     if (total_ > maxspeed_)
   73         fields_[2] = 0.0;
   74     else {
   75         fields_[2] = maxspeed_ - total_;
   76         total_ = maxspeed_;
   77     }
   78 
   79     setUsed(total_ - fields_[2], maxspeed_);
   80     pageindex_ = (pageindex_ + 1) % 2;
   81 }