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 // Copyright (c) 1996, 2004 by Massimiliano Ghilardi ( ghilardi@cibs.sns.it )
3 // 2007 by Samuel Thibault ( samuel.thibault@ens-lyon.org )
4 //
5 // This file may be distributed under terms of the GPL
6 //
7 
8 #include "pagemeter.h"
9 #include "xosview.h"
10 #include <fstream>
11 #include <stdlib.h>
12 #include <sys/types.h>
13 #include <sys/stat.h>
14 #include <unistd.h>
15 #include <error.h>
16 
17 extern "C" {
18 #include <mach/mach_traps.h>
19 #include <mach/mach_interface.h>
20 }
21 
22 PageMeter::PageMeter( XOSView *parent, float max )
23  : FieldMeterGraph( parent, 3, "PAGE", "IN/OUT/IDLE" ) {
24  for ( int i = 0 ; i < 2 ; i++ )
25  for ( int j = 0 ; j < 2 ; j++ )
26  pageinfo_[j][i] = 0;
27 
28  maxspeed_ = max;
29  pageindex_ = 0;
30 }
31 
32 PageMeter::~PageMeter( void ){
33 }
34 
35 void PageMeter::checkResources( void ){
37 
38  setfieldcolor( 0, parent_->getResource( "pageInColor" ) );
39  setfieldcolor( 1, parent_->getResource( "pageOutColor" ) );
40  setfieldcolor( 2, parent_->getResource( "pageIdleColor" ) );
41  priority_ = atoi (parent_->getResource( "pagePriority" ) );
42  maxspeed_ *= priority_ / 10.0;
43  dodecay_ = parent_->isResourceTrue( "pageDecay" );
44  useGraph_ = parent_->isResourceTrue( "pageGraph" );
45  SetUsedFormat (parent_->getResource("pageUsedFormat"));
46 }
47 
48 void PageMeter::checkevent( void ){
49  getpageinfo();
50  drawfields();
51 }
52 
54  {
55  int oldindex = (pageindex_+1)%2;
56  for ( int i = 0; i < 2; i++ )
57  {
58  if ( pageinfo_[oldindex][i] == 0 )
59  pageinfo_[oldindex][i] = pageinfo_[pageindex_][i];
60 
61  fields_[i] = pageinfo_[pageindex_][i] - pageinfo_[oldindex][i];
62  total_ += fields_[i];
63  }
64 
65  if ( total_ > maxspeed_ )
66  fields_[2] = 0.0;
67  else
68  {
69  fields_[2] = maxspeed_ - total_;
70  total_ = maxspeed_;
71  }
72 
74  pageindex_ = (pageindex_ + 1) % 2;
75  }
76 
77 void PageMeter::getpageinfo(void) {
78  struct vm_statistics vmstats;
79 
80  total_ = 0;
81  kern_return_t err;
82 
83  err = vm_statistics (mach_task_self(), &vmstats);
84  if (err) {
85  error (0, err, "vm_statistics");
86  parent_->done(1);
87  return;
88  }
89 
90  pageinfo_[pageindex_][0] = vmstats.pageins;
91  pageinfo_[pageindex_][1] = vmstats.pageouts;
92 
93  updateinfo();
94 }
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
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
void updateinfo(void)
Definition: pagemeter.cc:53
int pageindex_
Definition: pagemeter.h:24
void getpageinfo(void)
Definition: pagemeter.cc:49
float maxspeed_
Definition: pagemeter.h:25
PageMeter(XOSView *parent, double total)
Definition: pagemeter.cc:22
void checkevent(void)
Definition: pagemeter.cc:44
void checkResources(void)
Definition: pagemeter.cc:32
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