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)  

cpumeter.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 "cpumeter.h"
17 #include "kernel.h"
18 #include <stdlib.h>
19 #include <stdio.h>
20 #include <strings.h>
21 
22 
23 CPUMeter::CPUMeter( XOSView *parent, unsigned int nbr )
24  : FieldMeterGraph( parent, 5, "CPU", "USR/NICE/SYS/INT/FREE" ) {
25  nbr_ = nbr;
26  cpuindex_ = 0;
27  bzero(cputime_, 10 * sizeof(cputime_[0][0]));
28  BSDCPUInit();
29 
30  char t[8] = "CPU";
31  if (nbr_ > 0)
32  snprintf(t, 8, "CPU%d", nbr_ - 1);
33  title(t);
34 }
35 
37 }
38 
41 
42  setfieldcolor( 0, parent_->getResource("cpuUserColor") );
43  setfieldcolor( 1, parent_->getResource("cpuNiceColor") );
44  setfieldcolor( 2, parent_->getResource("cpuSystemColor") );
45  setfieldcolor( 3, parent_->getResource("cpuInterruptColor") );
46  setfieldcolor( 4, parent_->getResource("cpuFreeColor") );
47  priority_ = atoi( parent_->getResource("cpuPriority") );
48  dodecay_ = parent_->isResourceTrue("cpuDecay");
49  useGraph_ = parent_->isResourceTrue("cpuGraph");
50  SetUsedFormat( parent_->getResource("cpuUsedFormat") );
51 }
52 
53 void CPUMeter::checkevent( void ) {
54  getcputime();
55  drawfields();
56 }
57 
58 void CPUMeter::getcputime( void ) {
59  uint64_t tempCPU[CPUSTATES];
60  total_ = 0;
61 
62  BSDGetCPUTimes(tempCPU, nbr_);
63 
64  int oldindex = (cpuindex_ + 1) % 2;
65  for (int i = 0; i < CPUSTATES; i++) {
66  cputime_[cpuindex_][i] = tempCPU[i];
67  fields_[i] = cputime_[cpuindex_][i] - cputime_[oldindex][i];
68  total_ += fields_[i];
69  }
70  if (total_) {
72  cpuindex_ = (cpuindex_ + 1) % 2;
73  }
74 }
void checkevent(void)
Definition: cpumeter.cc:53
CPUMeter(XOSView *parent, unsigned int nbr)
Definition: cpumeter.cc:23
uint64_t cputime_[2][CPUSTATES]
Definition: cpumeter.h:44
void checkResources(void)
Definition: cpumeter.cc:39
~CPUMeter(void)
Definition: cpumeter.cc:36
void getcputime(void)
Definition: cpumeter.cc:58
unsigned int nbr_
Definition: cpumeter.h:45
unsigned int cpuindex_
Definition: cpumeter.h:45
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 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
const char * title(void)
Definition: meter.h:25
XOSView * parent_
Definition: meter.h:52
int isResourceTrue(const char *name)
Definition: xwin.h:89
const char * getResource(const char *name)
Definition: xwin.cc:362
void BSDGetCPUTimes(uint64_t *timeArray, unsigned int cpu)
Definition: kernel.cc:407
void BSDCPUInit()
Definition: kernel.cc:394