"Fossies" - the Fresh Open Source Software Archive

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

    1 //  
    2 //  Rewritten for Solaris by Arno Augustin 1999
    3 //  augustin@informatik.uni-erlangen.de
    4 //
    5 
    6 #include "diskmeter.h"
    7 #include <stdlib.h>
    8 
    9 
   10 DiskMeter::DiskMeter( XOSView *parent, kstat_ctl_t *kc, float max )
   11     : FieldMeterGraph( parent, 3, "DISK", "READ/WRITE/IDLE" )
   12 {
   13     _kc = kc;
   14     _read_prev = _write_prev = 0;
   15     _maxspeed = max;
   16     _disks = KStatList::getList(_kc, KStatList::DISKS);
   17 }
   18 
   19 DiskMeter::~DiskMeter( void )
   20 {
   21 }
   22 
   23 void DiskMeter::checkResources( void )
   24 {
   25     FieldMeterGraph::checkResources();
   26 
   27     setfieldcolor( 0, parent_->getResource("diskReadColor") );
   28     setfieldcolor( 1, parent_->getResource("diskWriteColor") );
   29     setfieldcolor( 2, parent_->getResource("diskIdleColor") );
   30     priority_ = atoi( parent_->getResource("diskPriority") );
   31     dodecay_ = parent_->isResourceTrue("diskDecay");
   32     useGraph_ = parent_->isResourceTrue("diskGraph");
   33     SetUsedFormat( parent_->getResource("diskUsedFormat") );
   34 }
   35 
   36 void DiskMeter::checkevent( void )
   37 {
   38     getdiskinfo();
   39     drawfields();
   40 }
   41 
   42 void DiskMeter::getdiskinfo( void )
   43 {
   44     total_ = _maxspeed;
   45     kstat_io_t kio;
   46     uint64_t read_curr = 0, write_curr = 0;
   47     _disks->update(_kc);
   48 
   49     IntervalTimerStop();
   50     for (unsigned int i = 0; i < _disks->count(); i++) {
   51         if ( kstat_read(_kc, (*_disks)[i], &kio) == -1 )
   52             continue;
   53         XOSDEBUG("%s: %llu bytes read %llu bytes written.\n",
   54                  (*_disks)[i]->ks_name, kio.nread, kio.nwritten);
   55         read_curr += kio.nread;
   56         write_curr += kio.nwritten;
   57     }
   58     if (_read_prev == 0)
   59         _read_prev = read_curr;
   60     if (_write_prev == 0)
   61         _write_prev = write_curr;
   62 
   63     double t = IntervalTimeInSecs();
   64     fields_[0] = (double)(read_curr - _read_prev) / t;
   65     fields_[1] = (double)(write_curr - _write_prev) / t;
   66 
   67     IntervalTimerStart();
   68     _read_prev = read_curr;
   69     _write_prev = write_curr;
   70 
   71     if (fields_[0] < 0)
   72         fields_[0] = 0;
   73     if (fields_[1] < 0)
   74         fields_[1] = 0;
   75     if (fields_[0] + fields_[1] > total_)
   76         total_ = fields_[0] + fields_[1];
   77     fields_[2] = total_ - (fields_[0] + fields_[1]);
   78     setUsed(fields_[0] + fields_[1], total_);
   79 }