"Fossies" - the Fresh Open Source Software Archive

Member "xosview-1.23/linux/intratemeter.cc" (11 Jul 2020, 2336 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 //  Based on bsd/intratemeter.* by
    5 //    Copyright (c) 1999 by Brian Grayson (bgrayson@netbsd.org)
    6 //  and on linux/intmeter.* by
    7 //    Copyright (c) 1994, 1995, 2006 by Mike Romberg ( mike.romberg@noaa.gov )
    8 //
    9 //  This file may be distributed under terms of the GPL
   10 //
   11 
   12 #include "intratemeter.h"
   13 #include "cpumeter.h"
   14 #include <stdlib.h>
   15 #include <fstream>
   16 #include <string>
   17 #include <iostream>
   18 
   19 static const char *INTFILE = "/proc/interrupts";
   20 
   21 
   22 IrqRateMeter::IrqRateMeter( XOSView *parent )
   23   : FieldMeterGraph( parent, 2, "IRQs", "IRQs per sec/IDLE", 1, 1, 0 ) {
   24   _lastirqs = 0;
   25   _cpucount = CPUMeter::countCPUs();
   26 }
   27 
   28 IrqRateMeter::~IrqRateMeter( void ) {
   29 }
   30 
   31 void IrqRateMeter::checkResources( void ) {
   32   FieldMeterGraph::checkResources();
   33   setfieldcolor( 0, parent_->getResource("irqrateUsedColor") );
   34   setfieldcolor( 1, parent_->getResource("irqrateIdleColor") );
   35   priority_ = atoi( parent_->getResource("irqratePriority") );
   36   dodecay_ = parent_->isResourceTrue("irqrateDecay");
   37   useGraph_ = parent_->isResourceTrue("irqrateGraph");
   38   SetUsedFormat( parent_->getResource("irqrateUsedFormat") );
   39   total_ = 2000;
   40 }
   41 
   42 void IrqRateMeter::checkevent( void ) {
   43   getinfo();
   44   drawfields();
   45 }
   46 
   47 void IrqRateMeter::getinfo( void ) {
   48   std::ifstream intfile(INTFILE);
   49   std::string line;
   50   unsigned long long count = 0;
   51   unsigned long tmp;
   52   const char *cur = NULL;
   53   char *end = NULL;
   54 
   55   if (!intfile) {
   56     std::cerr << "Can not open file : " << INTFILE << std::endl;
   57     parent_->done(1);
   58     return;
   59   }
   60 
   61   IntervalTimerStop();
   62   intfile.ignore(1024, '\n');
   63 
   64   // sum all interrupts on all cpus
   65   while ( !intfile.eof() ) {
   66     unsigned int i = 0;
   67     std::getline(intfile, line);
   68     if ( line.find_first_of("0123456789") > line.find_first_of(':') )
   69       break;  // reached non-numeric interrupts
   70     tmp = strtoul(line.c_str(), &end, 10);
   71     cur = end + 1;
   72     while (*cur && i++ < _cpucount) {
   73       tmp = strtoul(cur, &end, 10);
   74       count += tmp;
   75       cur = end;
   76     }
   77   }
   78   if (_lastirqs == 0)  // first run
   79     _lastirqs = count;
   80   fields_[0] = (count - _lastirqs) / IntervalTimeInSecs();
   81   IntervalTimerStart();
   82   _lastirqs = count;
   83 
   84   // Bump total, if needed.
   85   if (fields_[0] > total_)
   86     total_ = fields_[0];
   87 
   88   setUsed(fields_[0], total_);
   89 }