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)  

pagemeter.cc
Go to the documentation of this file.
1 //
2 // Initial port performed by Greg Onufer (exodus@cheers.bungi.com)
3 //
4 
5 #include "pagemeter.h"
6 #include <stdlib.h>
7 #include <sys/sysinfo.h>
8 
9 
10 PageMeter::PageMeter(XOSView *parent, kstat_ctl_t *_kc, float max)
11  : FieldMeterGraph( parent, 3, "PAGE", "IN/OUT/IDLE")
12 {
13  kc = _kc;
14 
15  for (int i = 0 ; i < 2 ; i++)
16  for (int j = 0 ; j < 2 ; j++)
17  pageinfo_[j][i] = 0;
18 
19  maxspeed_ = max;
20  pageindex_ = 0;
22 }
23 
25 {
26 }
27 
29 {
31 
32  setfieldcolor(0, parent_->getResource("pageInColor"));
33  setfieldcolor(1, parent_->getResource("pageOutColor"));
34  setfieldcolor(2, parent_->getResource("pageIdleColor"));
35  priority_ = atoi(parent_->getResource("pagePriority"));
36  maxspeed_ *= priority_ / 10.0;
37  dodecay_ = parent_->isResourceTrue("pageDecay");
38  useGraph_ = parent_->isResourceTrue("pageGraph");
39  SetUsedFormat(parent_->getResource("pageUsedFormat"));
40 }
41 
42 void PageMeter::checkevent(void)
43 {
44  getpageinfo();
45  drawfields();
46 }
47 
48 void PageMeter::getpageinfo(void)
49 {
50  cpu_stat_t cs;
51  total_ = 0;
52  pageinfo_[pageindex_][0] = 0; // pgin
53  pageinfo_[pageindex_][1] = 0; // pgout
54  cpustats->update(kc);
55 
56  for (unsigned int i = 0; i < cpustats->count(); i++) {
57  if (kstat_read(kc, (*cpustats)[i], &cs) == -1)
58  continue;
59  pageinfo_[pageindex_][0] += cs.cpu_vminfo.pgpgin;
60  pageinfo_[pageindex_][1] += cs.cpu_vminfo.pgpgout;
61  }
62 
63  int oldindex = (pageindex_ + 1) % 2;
64  for (int i = 0; i < 2; i++) {
65  if (pageinfo_[oldindex][i] == 0)
66  pageinfo_[oldindex][i] = pageinfo_[pageindex_][i];
67 
68  fields_[i] = pageinfo_[pageindex_][i] - pageinfo_[oldindex][i];
69  total_ += fields_[i];
70  }
71 
72  if (total_ > maxspeed_)
73  fields_[2] = 0.0;
74  else {
75  fields_[2] = maxspeed_ - total_;
76  total_ = maxspeed_;
77  }
78 
80  pageindex_ = (pageindex_ + 1) % 2;
81 }
virtual void drawfields(int mandatory=0)
virtual void checkResources(void)
double total_
Definition: fieldmeter.h:41
void setfieldcolor(int field, const char *color)
Definition: fieldmeter.cc:108
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
void update(kstat_ctl_t *kcp)
Definition: kstats.h:48
@ CPU_STAT
Definition: kstats.h:17
size_t count(void)
Definition: kstats.h:47
static KStatList * getList(kstat_ctl_t *kcp, module m)
Definition: kstats.h:23
int priority_
Definition: meter.h:54
XOSView * parent_
Definition: meter.h:52
~PageMeter(void)
Definition: pagemeter.cc:29
float pageinfo_[2][2]
Definition: pagemeter.h:23
KStatList * cpustats
Definition: pagemeter.h:30
int pageindex_
Definition: pagemeter.h:24
void getpageinfo(void)
Definition: pagemeter.cc:49
float maxspeed_
Definition: pagemeter.h:25
kstat_ctl_t * kc
Definition: pagemeter.h:31
PageMeter(XOSView *parent, double total)
Definition: pagemeter.cc:22
void checkevent(void)
Definition: pagemeter.cc:44
void checkResources(void)
Definition: pagemeter.cc:32
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