"Fossies" - the Fresh Open Source Software Archive

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

    1 //
    2 //  Copyright (c) 2014 by Tomi Tapper <tomi.o.tapper@jyu.fi>
    3 //
    4 //  File based on bsd/intratemeter.* by
    5 //  Copyright (c) 1999 by Brian Grayson (bgrayson@netbsd.org)
    6 //
    7 //  This file may be distributed under terms of the GPL
    8 //
    9 //
   10 
   11 #include "intratemeter.h"
   12 #include <stdlib.h>
   13 
   14 
   15 IrqRateMeter::IrqRateMeter(XOSView *parent, kstat_ctl_t *kc)
   16     : FieldMeterGraph(parent, 2, "IRQs", "IRQs per sec/IDLE", 1, 1, 0)
   17 {
   18     _lastirqcount = 0;
   19     _kc = kc;
   20     _cpus = KStatList::getList(_kc, KStatList::CPU_SYS);
   21 }
   22 
   23 IrqRateMeter::~IrqRateMeter(void)
   24 {
   25 }
   26 
   27 void IrqRateMeter::checkResources(void)
   28 {
   29     FieldMeterGraph::checkResources();
   30     setfieldcolor(0, parent_->getResource("irqrateUsedColor"));
   31     setfieldcolor(1, parent_->getResource("irqrateIdleColor"));
   32     priority_ = atoi(parent_->getResource("irqratePriority"));
   33     dodecay_ = parent_->isResourceTrue("irqrateDecay");
   34     useGraph_ = parent_->isResourceTrue("irqrateGraph");
   35     SetUsedFormat(parent_->getResource("irqrateUsedFormat"));
   36     total_ = 2000;
   37 }
   38 
   39 void IrqRateMeter::checkevent(void)
   40 {
   41     getinfo();
   42     drawfields();
   43 }
   44 
   45 void IrqRateMeter::getinfo(void)
   46 {
   47     kstat_named_t *k;
   48     uint64_t irqcount = 0;
   49 
   50     _cpus->update(_kc);
   51     IntervalTimerStop();
   52     for (size_t i = 0; i < _cpus->count(); i++) {
   53         if (kstat_read(_kc, (*_cpus)[i], NULL) == -1) {
   54             parent_->done(1);
   55             return;
   56         }
   57         k = (kstat_named_t *)kstat_data_lookup((*_cpus)[i], "intr");
   58         if (k == NULL) {
   59             parent_->done(1);
   60             return;
   61         }
   62         irqcount += kstat_to_ui64(k);
   63     }
   64     if (_lastirqcount == 0)
   65         _lastirqcount = irqcount;
   66 
   67     fields_[0] = (irqcount - _lastirqcount) / IntervalTimeInSecs();
   68     _lastirqcount = irqcount;
   69     IntervalTimerStart();
   70 
   71     if (fields_[0] > total_)
   72         total_ = fields_[0];
   73 
   74     setUsed(fields_[0], total_);
   75 }
   76