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)  

swapmeter.cc
Go to the documentation of this file.
1 //
2 // Copyright (c) 1994, 1995 by Mike Romberg ( romberg@fsl.noaa.gov )
3 //
4 // NetBSD port:
5 // Copyright (c) 1995, 1996, 1997-2002 by Brian Grayson (bgrayson@netbsd.org)
6 //
7 // This file was written by Brian Grayson for the NetBSD and xosview
8 // projects.
9 // This file may be distributed under terms of the GPL or of the BSD
10 // license, whichever you choose. The full license notices are
11 // contained in the files COPYING.GPL and COPYING.BSD, which you
12 // should have received. If not, contact one of the xosview
13 // authors for a copy.
14 //
15 
16 #include "swapmeter.h"
17 #include "kernel.h"
18 #include <stdlib.h>
19 
20 
22  : FieldMeterGraph( parent, 2, "SWAP", "USED/FREE" ) {
23  BSDSwapInit();
24 }
25 
27 }
28 
31 
32  setfieldcolor( 0, parent_->getResource("swapUsedColor") );
33  setfieldcolor( 1, parent_->getResource("swapFreeColor") );
34  priority_ = atoi( parent_->getResource("swapPriority") );
35  dodecay_ = parent_->isResourceTrue("swapDecay");
36  useGraph_ = parent_->isResourceTrue("swapGraph");
37  SetUsedFormat( parent_->getResource("swapUsedFormat") );
38 }
39 
40 void SwapMeter::checkevent( void ) {
41  getswapinfo();
42  drawfields();
43 }
44 
45 void SwapMeter::getswapinfo( void ) {
46  uint64_t total = 0, used = 0;
47 
48  BSDGetSwapInfo(&total, &used);
49 
50  total_ = (double)total;
51  if ( total_ == 0.0 )
52  total_ = 1.0; /* We don't want any division by zero, now, do we? :) */
53  fields_[0] = (double)used;
54  fields_[1] = total_;
55 
56  setUsed(fields_[0], total_);
57 }
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
void checkResources(void)
Definition: swapmeter.cc:29
void checkevent(void)
Definition: swapmeter.cc:40
void getswapinfo(void)
Definition: swapmeter.cc:45
SwapMeter(XOSView *parent)
Definition: swapmeter.cc:21
~SwapMeter(void)
Definition: swapmeter.cc:26
int isResourceTrue(const char *name)
Definition: xwin.h:89
const char * getResource(const char *name)
Definition: xwin.cc:362
int BSDSwapInit()
Definition: kernel.cc:525
void BSDGetSwapInfo(uint64_t *total, uint64_t *used)
Definition: kernel.cc:531