"Fossies" - the Fresh Open Source Software Archive

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

    1 //
    2 //  Copyright (c) 1994, 1995 by Mike Romberg ( romberg@fsl.noaa.gov )
    3 //
    4 //  This file may be distributed under terms of the GPL
    5 //
    6 
    7 #include "intmeter.h"
    8 #include "kernel.h"
    9 #include <stdlib.h>
   10 #include <strings.h>
   11 #include <sstream>
   12 
   13 
   14 IntMeter::IntMeter( XOSView *parent, const char *, const char *, int dolegends, int dousedlegends )
   15     : BitMeter( parent, "INTS", "IRQs", 1, dolegends, dousedlegends ) {
   16     if (!BSDIntrInit())
   17         disableMeter();
   18     irqcount_ = BSDNumInts();
   19     irqs_ = (uint64_t *)calloc(irqcount_ + 1, sizeof(uint64_t));
   20     lastirqs_ = (uint64_t *)calloc(irqcount_ + 1, sizeof(uint64_t));
   21     inbrs_ = (unsigned int *)calloc(irqcount_ + 1, sizeof(int));
   22     updateirqcount(true);
   23 }
   24 
   25 IntMeter::~IntMeter( void ) {
   26     free(irqs_);
   27     free(lastirqs_);
   28     free(inbrs_);
   29 }
   30 
   31 void IntMeter::checkevent( void ) {
   32     getirqs();
   33 
   34     for (uint i = 0 ; i <= irqcount_ ; i++) {
   35         if (inbrs_[i] != 0) {
   36             if (realintnum_.find(i) == realintnum_.end()) {   // new interrupt number
   37                 updateirqcount();
   38                 return;
   39             }
   40             bits_[realintnum_[i]] = ((irqs_[i] - lastirqs_[i]) != 0);
   41             lastirqs_[i] = irqs_[i];
   42         }
   43     }
   44     bzero(inbrs_, (irqcount_ + 1) * sizeof(inbrs_[0]));
   45     bzero(irqs_, (irqcount_ + 1) * sizeof(irqs_[0]));
   46 
   47     BitMeter::checkevent();
   48 }
   49 
   50 void IntMeter::checkResources( void ) {
   51     BitMeter::checkResources();
   52     onColor_  = parent_->allocColor( parent_->getResource( "intOnColor" ) );
   53     offColor_ = parent_->allocColor( parent_->getResource( "intOffColor" ) );
   54     priority_ = atoi( parent_->getResource( "intPriority" ) );
   55 }
   56 
   57 void IntMeter::getirqs( void ) {
   58     BSDGetIntrStats(irqs_, inbrs_);
   59 }
   60 
   61 void IntMeter::updateirqcount( bool init ) {
   62     int count = 16;
   63 
   64     if (init) {
   65         getirqs();
   66         for (int i = 0; i < 16; i++)
   67             realintnum_[i] = i;
   68     }
   69     for (uint i = 16; i <= irqcount_; i++) {
   70         if (inbrs_[i] != 0) {
   71             realintnum_[i] = count++;
   72             inbrs_[i] = 0;
   73         }
   74     }
   75     setNumBits(count);
   76 
   77     // Build the legend.
   78     std::ostringstream os;
   79     os << "0";
   80     if (realintnum_.upper_bound(15) == realintnum_.end()) // only 16 ints
   81         os << "-15";
   82     else {
   83         int prev = 15, prev2 = 14;
   84         for (std::map<int,int>::const_iterator it = realintnum_.upper_bound(15),
   85              end = realintnum_.end(); it != end; ++it) {
   86             if ( &*it == &*realintnum_.rbegin() ) { // last element
   87                 if (it->first == prev + 1)
   88                     os << "-" ;
   89                 else {
   90                     if (prev == prev2 + 1)
   91                         os << "-" << prev;
   92                     os << "," ;
   93                 }
   94                 os << it->first;
   95             }
   96             else {
   97                 if (it->first != prev + 1) {
   98                     if (prev == prev2 + 1)
   99                         os << "-" << prev;
  100                     os << "," << it->first ;
  101                 }
  102             }
  103             prev2 = prev;
  104             prev = it->first;
  105         }
  106         os << std::ends;
  107     }
  108     legend(os.str().c_str());
  109 }