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