1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
/**********************************************************************/
/* TimeMon (c) 1994 Helmut Maierhofer */
/* KDE-ified M. Maierhofer 1998 */
/**********************************************************************/
/*
* sample.h
*
* Definitions for the system dependent sampling class (currently relies
* on the linux /proc filesystem).
*/
#ifndef SAMPLE_H
#define SAMPLE_H
// -- global constants ---------------------------------------------------
#define MAX_CPU 16 // max number of CPUS in an SMP machine
// we get the status for
// -- forward declaration ------------------------------------------------
class KTimeMon;
#ifdef USE_SOLARIS
struct kstat_ctl;
#endif
// -- class declaration --------------------------------------------------
/*
* KSample
*
* This class is responsible for reading the /proc file system and parsing
* the system information.
*/
class KSample {
public:
// -- Sample declaration -----------------------------------------------
struct Sample {
unsigned long cputotal;
unsigned long user, nice, kernel, iowait, idle;
int cpus;
unsigned long smptotal[MAX_CPU], smpbusy[MAX_CPU];
unsigned long mtotal, free, buffers, cached, mkernel, used;
unsigned long stotal, sused, sfree;
void fill(unsigned scale); // fill sample with some fake values
};
struct MemStats {
const char *name;
unsigned long *stat;
};
KSample(KTimeMon *timemon, bool autoScale, unsigned pageScale,
unsigned swapScale, unsigned ctxScale);
virtual ~KSample();
void setScaling(bool autoScale, unsigned pageScale,
unsigned swapScale, unsigned ctxScale);
Sample getSample(unsigned scale); // returns the current sample
Sample getRawSample(); // returns unscaled sample
void updateSample(); // updates the internally stored sample
private:
void readSample(); // reads a new sample from /proc
unsigned long doScale(unsigned long value, unsigned scale1,
unsigned long scale2);
// converts pages to MB
void makeMBytes(unsigned long &pages);
void fatal(const TQString& msg);
void nonfatal(const TQString& msg);
KTimeMon *timemon;
#ifdef __linux__
int memFD, statFD;
#elif defined(USE_SOLARIS)
struct kstat_ctl *kc;
bool warned;
#endif
#if defined(USE_SOLARIS) || defined(__osf__)
unsigned long pagesPerMB;
#endif
Sample sample, oldSample;
unsigned pageScale, swapScale, cxScale;
bool autoscale;
struct MemStats memstats[7];
};
#endif // SAMPLE_H
|