|
Lines 8-14
Link Here
|
| 8 |
static ProcStats ps; |
8 |
static ProcStats ps; |
| 9 |
int use_proc_diskstats; |
9 |
int use_proc_diskstats; |
| 10 |
|
10 |
|
| 11 |
void pstat_init(struct pstat *pst, int nslice, float update_interval) { |
11 |
void pstat_init(struct pstat *pst, long nslice, float update_interval) { |
| 12 |
pst->nslice = nslice; |
12 |
pst->nslice = nslice; |
| 13 |
ALLOC_VEC(pst->slices, nslice); |
13 |
ALLOC_VEC(pst->slices, nslice); |
| 14 |
pst->cur_slice = 0; |
14 |
pst->cur_slice = 0; |
|
Lines 17-23
void pstat_init(struct pstat *pst, int n
Link Here
|
| 17 |
} |
17 |
} |
| 18 |
|
18 |
|
| 19 |
float pstat_current(struct pstat *pst) { |
19 |
float pstat_current(struct pstat *pst) { |
| 20 |
int idx = pst->cur_slice ? pst->cur_slice-1 : pst->nslice-1; |
20 |
long idx = pst->cur_slice ? pst->cur_slice-1 : pst->nslice-1; |
| 21 |
return pst->slices[idx]/pst->update_interval; |
21 |
return pst->slices[idx]/pst->update_interval; |
| 22 |
} |
22 |
} |
| 23 |
|
23 |
|
|
Lines 101-113
void update_stats() {
Link Here
|
| 101 |
if (!Prefs.debug_disk_rd) { |
101 |
if (!Prefs.debug_disk_rd) { |
| 102 |
pstat_add(&ps.disk_read, nr); |
102 |
pstat_add(&ps.disk_read, nr); |
| 103 |
} else { |
103 |
} else { |
| 104 |
static int cntr = 0; cntr+=(rand()%30) == 0 ? Prefs.debug_disk_rd : 0; |
104 |
static long cntr = 0; cntr+=(rand()%30) == 0 ? Prefs.debug_disk_rd : 0; |
| 105 |
pstat_add(&ps.disk_read, nr + cntr); |
105 |
pstat_add(&ps.disk_read, nr + cntr); |
| 106 |
} |
106 |
} |
| 107 |
if (!Prefs.debug_disk_wr) { |
107 |
if (!Prefs.debug_disk_wr) { |
| 108 |
pstat_add(&ps.disk_write, nw); |
108 |
pstat_add(&ps.disk_write, nw); |
| 109 |
} else { |
109 |
} else { |
| 110 |
static int cntw = 0; cntw+=(rand()%30) == 0 ? Prefs.debug_disk_wr : 0; |
110 |
static long cntw = 0; cntw+=(rand()%30) == 0 ? Prefs.debug_disk_wr : 0; |
| 111 |
pstat_add(&ps.disk_write, nw + cntw); |
111 |
pstat_add(&ps.disk_write, nw + cntw); |
| 112 |
} |
112 |
} |
| 113 |
readok = 2; |
113 |
readok = 2; |
|
Lines 121-127
void update_stats() {
Link Here
|
| 121 |
pstat_add(&ps.swap_in, nr); |
121 |
pstat_add(&ps.swap_in, nr); |
| 122 |
pstat_add(&ps.swap_out, nw); |
122 |
pstat_add(&ps.swap_out, nw); |
| 123 |
} else { |
123 |
} else { |
| 124 |
static int cnt = 0; cnt+=Prefs.debug_swapio; |
124 |
static long cnt = 0; cnt+=Prefs.debug_swapio; |
| 125 |
pstat_add(&ps.swap_in, nr + cnt); |
125 |
pstat_add(&ps.swap_in, nr + cnt); |
| 126 |
pstat_add(&ps.swap_out, nw + cnt); |
126 |
pstat_add(&ps.swap_out, nw + cnt); |
| 127 |
} |
127 |
} |
|
Lines 144-153
void init_stats(float update_interval) {
Link Here
|
| 144 |
char s[512]; |
144 |
char s[512]; |
| 145 |
FILE *f; |
145 |
FILE *f; |
| 146 |
|
146 |
|
| 147 |
pstat_init(&ps.swap_in, (int)(0.5/update_interval)+1, update_interval); |
147 |
pstat_init(&ps.swap_in, (long)(0.5/update_interval)+1, update_interval); |
| 148 |
pstat_init(&ps.swap_out, (int)(0.5/update_interval)+1, update_interval); |
148 |
pstat_init(&ps.swap_out, (long)(0.5/update_interval)+1, update_interval); |
| 149 |
pstat_init(&ps.disk_read, (int)(0.5/update_interval)+1, update_interval); |
149 |
pstat_init(&ps.disk_read, (long)(0.5/update_interval)+1, update_interval); |
| 150 |
pstat_init(&ps.disk_write, (int)(0.5/update_interval)+1, update_interval); |
150 |
pstat_init(&ps.disk_write, (long)(0.5/update_interval)+1, update_interval); |
| 151 |
f = fopen("/proc/swaps","r"); |
151 |
f = fopen("/proc/swaps","r"); |
| 152 |
//if (!f) { perror("/proc/swaps"); exit(1); } |
152 |
//if (!f) { perror("/proc/swaps"); exit(1); } |
| 153 |
if (f) { |
153 |
if (f) { |