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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
diff -u -r xosview-1.8.0/linux/diskmeter.cc xosview-1.8.0-kai/linux/diskmeter.cc
--- xosview-1.8.0/linux/diskmeter.cc 1999-11-07 21:30:58.000000000 +0100
+++ xosview-1.8.0-kai/linux/diskmeter.cc 2003-02-27 03:50:54.000000000 +0100
@@ -12,6 +12,8 @@
#include <stdlib.h>
static const char STATFILENAME[] = "/proc/stat";
+// kernel >= 2.5 support
+static const char VMSTATFILENAME[] = "/proc/vmstat";
DiskMeter::DiskMeter( XOSView *parent, float max ) : FieldMeterGraph(
parent, 3, "DISK", "READ/WRITE/IDLE")
@@ -50,25 +52,54 @@
IntervalTimerStop();
total_ = maxspeed_;
char buf[1024];
+ unsigned char new_kernel = 1;
+ ifstream vmstats( VMSTATFILENAME );
ifstream stats( STATFILENAME );
- if ( !stats )
+ if ( new_kernel && !vmstats )
{
- cerr <<"Can not open file : " <<STATFILENAME <<endl;
- exit( 1 );
+ new_kernel = 0;
}
- // Find the line with 'page'
- stats >> buf;
- while (strncmp(buf, "page", 9))
+ if ( !new_kernel && !stats )
{
- stats.ignore(1024, '\n');
- stats >> buf;
+ cerr <<"Can not open file : " <<STATFILENAME <<endl;
+ exit( 1 );
}
- // read values
unsigned long one, two;
- stats >> one >> two;
+
+ if (new_kernel) {
+ vmstats >> buf;
+ // kernel >= 2.5
+ while (!vmstats.eof() && strncmp(buf, "pgpgin", 7))
+ {
+ vmstats.ignore(1024, '\n');
+ vmstats >> buf;
+ }
+
+ // read first value
+ vmstats >> one;
+
+ while (!vmstats.eof() && strncmp(buf, "pgpgout", 7))
+ {
+ vmstats.ignore(1024, '\n');
+ vmstats >> buf;
+ }
+
+ // read second value
+ vmstats >> two;
+ } else {
+ stats >> buf;
+ while (strncmp(buf, "page", 9))
+ {
+ stats.ignore(1024, '\n');
+ stats >> buf;
+ }
+
+ // read values
+ stats >> one >> two;
+ }
// assume each "unit" is 1k.
// This is true for ext2, but seems to be 512 bytes
Only in xosview-1.8.0/linux/memstat: Makefile
diff -u -r xosview-1.8.0/linux/pagemeter.cc xosview-1.8.0-kai/linux/pagemeter.cc
--- xosview-1.8.0/linux/pagemeter.cc 1999-02-24 23:28:18.000000000 +0100
+++ xosview-1.8.0-kai/linux/pagemeter.cc 2003-02-27 03:02:17.000000000 +0100
@@ -13,6 +13,8 @@
static const char STATFILENAME[] = "/proc/stat";
+// kernel >= 2.5 support
+static const char VMSTATFILENAME[] = "/proc/vmstat";
PageMeter::PageMeter( XOSView *parent, float max )
@@ -49,18 +51,41 @@
void PageMeter::getpageinfo( void ){
total_ = 0;
char buf[1024];
+ unsigned char new_kernel = 1;
+
+ ifstream vmstats( VMSTATFILENAME );
ifstream stats( STATFILENAME );
- if ( !stats ){
- cerr <<"Cannot open file : " <<STATFILENAME <<endl;
- exit( 1 );
+ if ( new_kernel && !vmstats ){
+ new_kernel = 0;
+ }
+
+ if ( !new_kernel && !stats ) {
+ cerr <<"Cannot open file : " <<STATFILENAME <<endl;
+ exit( 1 );
}
- do {
- stats >>buf;
- } while (strncasecmp(buf, "swap", 5));
+ if ( new_kernel ) {
+ // kernel >= 2.5
+ do {
+ vmstats >>buf;
+ } while (!vmstats.eof() && strncasecmp(buf, "pswpin", 7));
- stats >>pageinfo_[pageindex_][0] >>pageinfo_[pageindex_][1];
+ vmstats >>pageinfo_[pageindex_][0];
+
+ do {
+ vmstats >>buf;
+ } while (!vmstats.eof() && strncasecmp(buf, "pswpout", 8)) ;
+
+ vmstats >>pageinfo_[pageindex_][1];
+ } else {
+ // kernel < 2.5
+ do {
+ stats >>buf;
+ } while (strncasecmp(buf, "swap", 5));
+
+ stats >>pageinfo_[pageindex_][0] >>pageinfo_[pageindex_][1];
+ }
int oldindex = (pageindex_+1)%2;
|