"Fossies" - the Fresh Open Source Software Archive

Member "xosview-1.23/bsd/diskmeter.cc" (11 Jul 2020, 3034 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 //  Copyright (c) 1995, 1996, 1997-2002 by Brian Grayson (bgrayson@netbsd.org)
    3 //
    4 //  This file was written by Brian Grayson for the NetBSD and xosview
    5 //    projects.
    6 //  This file may be distributed under terms of the GPL or of the BSD
    7 //    license, whichever you choose.  The full license notices are
    8 //    contained in the files COPYING.GPL and COPYING.BSD, which you
    9 //    should have received.  If not, contact one of the xosview
   10 //    authors for a copy.
   11 //
   12 
   13 #include "diskmeter.h"
   14 #include "kernel.h"
   15 #include <stdlib.h>
   16 #include <err.h>
   17 
   18 
   19 DiskMeter::DiskMeter( XOSView *parent, double max )
   20     : FieldMeterGraph( parent, 3, "DISK", "READ/WRITE/IDLE" ) {
   21     dodecay_ = 0;
   22     maxBandwidth_ = max;
   23     total_ = max;
   24     if (!BSDDiskInit())
   25         disableMeter();
   26 
   27     /* Since at the first call, it will look like we transferred a
   28      * gazillion bytes, let's reset total_ again and do another
   29      * call.  This will force total_ to be something reasonable.  */
   30     getstats();
   31     total_ = max;
   32     getstats();
   33     IntervalTimerStart();
   34     /* By doing this check, we eliminate the startup situation where
   35      * all fields are 0, and total is 0, leading to nothing being drawn
   36      * on the meter.  So, make it look like nothing was transferred,
   37      * out of a total of 1 bytes.  */
   38     fields_[0] = fields_[1] = 0.0;
   39     total_ = 1.0;
   40     fields_[2] = total_;
   41 }
   42 
   43 DiskMeter::~DiskMeter( void ) {
   44 }
   45 
   46 void DiskMeter::checkResources( void ) {
   47     FieldMeterGraph::checkResources();
   48 
   49     setfieldcolor( 0, parent_->getResource("diskReadColor") );
   50     setfieldcolor( 1, parent_->getResource("diskWriteColor") );
   51     setfieldcolor( 2, parent_->getResource("diskIdleColor") );
   52     priority_ = atoi( parent_->getResource("diskPriority") );
   53     dodecay_ = parent_->isResourceTrue("diskDecay");
   54     useGraph_ = parent_->isResourceTrue("diskGraph");
   55     SetUsedFormat( parent_->getResource("diskUsedFormat") );
   56 }
   57 
   58 void DiskMeter::checkevent( void ) {
   59     getstats();
   60     drawfields();
   61 }
   62 
   63 void DiskMeter::getstats( void ) {
   64     uint64_t reads = 0, writes = 0;
   65     //  Reset to desired full-scale settings.
   66     total_ = maxBandwidth_;
   67 
   68     IntervalTimerStop();
   69     BSDGetDiskXFerBytes(&reads, &writes);
   70 
   71     /*  Adjust this to bytes/second.  */
   72 #if defined(HAVE_DEVSTAT)
   73     fields_[0] = reads / IntervalTimeInSecs();
   74     fields_[1] = writes / IntervalTimeInSecs();
   75 #else
   76     fields_[0] = (reads - prevreads_) / IntervalTimeInSecs();
   77     fields_[1] = (writes - prevwrites_) / IntervalTimeInSecs();
   78     prevreads_ = reads;
   79     prevwrites_ = writes;
   80 #endif
   81     IntervalTimerStart();
   82 
   83     /*  Adjust in case of first call.  */
   84     if (fields_[0] < 0.0)
   85         fields_[0] = 0.0;
   86     if (fields_[1] < 0.0)
   87         fields_[1] = 0.0;
   88 
   89     /*  Adjust total_ if needed.  */
   90     if (fields_[0] + fields_[1] > total_)
   91         total_ = fields_[0] + fields_[1];
   92 
   93     fields_[2] = total_ - (fields_[0] + fields_[1]);
   94     if (fields_[0] < 0.0)
   95         warnx("diskmeter: fields[0] of %f is < 0!", fields_[0]);
   96     if (fields_[1] < 0.0)
   97         warnx("diskmeter: fields[1] of %f is < 0!", fields_[1]);
   98     if (fields_[2] < 0.0)
   99         warnx("diskmeter: fields[2] of %f is < 0!", fields_[2]);
  100 
  101     setUsed(fields_[0] + fields_[1], total_);
  102 }