xosview  1.23
About: xosview is an X Windows based system monitor (cpu, memory, swap and network usage; interrupt and serial activities; load average).
  Fossies Dox: xosview-1.23.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

intmeter.cc
Go to the documentation of this file.
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();
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 
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
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 
48 }
49 
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 ) {
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 }
unsigned long onColor_
Definition: bitmeter.h:30
void setNumBits(int n)
Definition: bitmeter.cc:23
unsigned long offColor_
Definition: bitmeter.h:30
char * bits_
Definition: bitmeter.h:31
void checkResources(void)
Definition: bitmeter.cc:43
void disableMeter(void)
Definition: bitmeter.cc:35
void checkevent(void)
Definition: bitmeter.cc:47
uint64_t * irqs_
Definition: intmeter.h:26
void getirqs(void)
Definition: intmeter.cc:57
IntMeter(XOSView *parent, const char *title="", const char *legend="", int dolegends=0, int dousedlegends=0)
Definition: intmeter.cc:14
uint64_t * lastirqs_
Definition: intmeter.h:26
void checkResources(void)
Definition: intmeter.cc:50
void checkevent(void)
Definition: intmeter.cc:31
std::map< int, int > realintnum_
Definition: intmeter.h:29
void updateirqcount(bool init=false)
Definition: intmeter.cc:61
unsigned int * inbrs_
Definition: intmeter.h:27
unsigned int irqcount_
Definition: intmeter.h:28
~IntMeter(void)
Definition: intmeter.cc:25
int priority_
Definition: meter.h:54
const char * legend(void)
Definition: meter.h:27
XOSView * parent_
Definition: meter.h:52
unsigned long allocColor(const char *name)
Definition: xwin.cc:383
const char * getResource(const char *name)
Definition: xwin.cc:362
int BSDNumInts()
Definition: kernel.cc:873
void BSDGetIntrStats(uint64_t *intrCount, unsigned int *intrNbrs)
Definition: kernel.cc:976
int BSDIntrInit()
Definition: kernel.cc:855