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)  

gfxmeter.cc
Go to the documentation of this file.
1 //
2 // Initial port performed by Stefan Eilemann (eilemann@gmail.com)
3 //
4 
5 #include "gfxmeter.h"
6 #include "xosview.h"
7 
8 #include <stdlib.h>
9 #include <unistd.h>
10 #include <invent.h>
11 #include <iostream>
12 
13 using namespace std;
14 
15 // GfxMeter display swapbuffers per second. max is base rate for one gfx pipe.
16 
18  : FieldMeterGraph(parent, 2, "GFX","SWAPBUF/S", 1, 1, 0 )
19 {
20  lastalarmstate = -1;
21  total_ = 0;
22  _nPipes = nPipes();
23  total_ = _nPipes * max;
24 
25  if ( total_==0 ) {
26  parent_->done(1);
27  return;
28  }
29 }
30 
32 {
33 }
34 
36 {
37  int _nPipes = 0;
38 
39  setinvent();
40  for( inventory_t *inv = getinvent(); inv != NULL; inv = getinvent() )
41  {
42  if ( inv->inv_class==INV_GRAPHICS )
43  {
44  _nPipes++;
45  }
46  }
47  return _nPipes;
48 }
49 
51 {
53 
54  swapgfxcol_ = parent_->allocColor(parent_->getResource( "gfxSwapColor" ));
55  warngfxcol_ = parent_->allocColor(parent_->getResource( "gfxWarnColor" ));
56  critgfxcol_ = parent_->allocColor(parent_->getResource( "gfxCritColor" ));
57 
58  setfieldcolor(0, parent_->getResource( "gfxSwapColor" ));
59  setfieldcolor(1, parent_->getResource("gfxIdleColor"));
60  priority_ = atoi (parent_->getResource("gfxPriority"));
61  useGraph_ = parent_->isResourceTrue("gfxGraph");
62  dodecay_ = parent_->isResourceTrue( "gfxDecay" );
63  SetUsedFormat(parent_->getResource("gfxUsedFormat"));
64 
65  warnThreshold = atoi (parent_->getResource("gfxWarnThreshold")) * _nPipes;
66  critThreshold = atoi (parent_->getResource("gfxCritThreshold")) * _nPipes;
67 
68  if (dodecay_){
69  // Warning: Since the gfxmeter changes scale occasionally, old
70  // decay values need to be rescaled. However, if they are rescaled,
71  // they could go off the edge of the screen. Thus, for now, to
72  // prevent this whole problem, the gfx meter can not be a decay
73  // meter. The gfx is a decaying average kind of thing anyway,
74  // so having a decaying gfx average is redundant.
75  std::cerr << "Warning: The gfxmeter can not be configured as a decay\n"
76  << " meter. See the source code (" <<__FILE__<< ") for further\n"
77  << " details.\n";
78  dodecay_ = 0;
79  }
80 }
81 
83 {
84  getgfxinfo();
85  drawfields();
86 }
87 
89 {
91 
92  fields_[0] = (float)gi->swapBuf;
93 
94  if ( fields_[0] < warnThreshold )
95  alarmstate = 0;
96  else
97  if ( fields_[0] >= critThreshold )
98  alarmstate = 2;
99  else
100  alarmstate = 1;
101 
102  if ( alarmstate != lastalarmstate )
103  {
104  if ( alarmstate == 0 )
106  else
107  if ( alarmstate == 1 )
109  else
111  drawlegend();
113  }
114 
115  if ( fields_[0]*5.0<total_ )
116  total_ = fields_[0];
117  else
118  if ( fields_[0]>total_ )
119  total_ = fields_[0]*5.0;
120 
121  if ( total_ < 1.0)
122  total_ = 1.0;
123 
124  fields_[1] = (float) (total_ - fields_[0]);
125 
126  setUsed(fields_[0], (float) 1.0);
127 }
virtual void checkResources(void)
virtual void drawfields(int mandatory=0)
double total_
Definition: fieldmeter.h:41
void setfieldcolor(int field, const char *color)
Definition: fieldmeter.cc:108
void drawlegend(void)
Definition: fieldmeter.cc:136
void setUsed(double val, double total)
Definition: fieldmeter.cc:76
double * fields_
Definition: fieldmeter.h:40
void SetUsedFormat(const char *const str)
Definition: fieldmeter.cc:60
int _nPipes
Definition: gfxmeter.h:31
int alarmstate
Definition: gfxmeter.h:30
int lastalarmstate
Definition: gfxmeter.h:30
void checkResources(void)
Definition: gfxmeter.cc:50
static int nPipes(void)
Definition: gfxmeter.cc:35
GfxMeter(XOSView *parent, int max)
Definition: gfxmeter.cc:17
unsigned long swapgfxcol_
Definition: gfxmeter.h:27
void getgfxinfo(void)
Definition: gfxmeter.cc:88
int warnThreshold
Definition: gfxmeter.h:30
void checkevent(void)
Definition: gfxmeter.cc:82
unsigned long warngfxcol_
Definition: gfxmeter.h:27
~GfxMeter(void)
Definition: gfxmeter.cc:31
unsigned long critgfxcol_
Definition: gfxmeter.h:27
int critThreshold
Definition: gfxmeter.h:30
int priority_
Definition: meter.h:54
XOSView * parent_
Definition: meter.h:52
static SarMeter * Instance()
Definition: sarmeter.cc:11
GfxInfo * getGfxInfo(void)
Definition: sarmeter.h:48
unsigned long allocColor(const char *name)
Definition: xwin.cc:383
int done(void)
Definition: xwin.h:29
int isResourceTrue(const char *name)
Definition: xwin.h:89
const char * getResource(const char *name)
Definition: xwin.cc:362
static const int max
Definition: intmeter.cc:17
unsigned int swapBuf
Definition: sarmeter.h:38