Lines 115-121
Link Here
|
115 |
|
115 |
|
116 |
void update_net_stats() { |
116 |
void update_net_stats() { |
117 |
static int rep; |
117 |
static int rep; |
|
|
118 |
// FIXME: arbitrary size chosen to keep code simple. |
119 |
static float net_rec[15]; |
120 |
static float net_trans[15]; |
118 |
unsigned int i; |
121 |
unsigned int i; |
|
|
122 |
unsigned int curtmp; |
119 |
char buf[256]; |
123 |
char buf[256]; |
120 |
double delta; |
124 |
double delta; |
121 |
|
125 |
|
Lines 174-182
Link Here
|
174 |
ns->trans += (t - ns->last_read_trans); |
178 |
ns->trans += (t - ns->last_read_trans); |
175 |
ns->last_read_trans = t; |
179 |
ns->last_read_trans = t; |
176 |
|
180 |
|
|
|
181 |
|
182 |
|
177 |
/* calculate speeds */ |
183 |
/* calculate speeds */ |
178 |
ns->recv_speed = (ns->recv - last_recv) / delta; |
184 |
net_rec[0] = (ns->recv - last_recv) / delta; |
179 |
ns->trans_speed = (ns->trans - last_trans) / delta; |
185 |
net_trans[0] = (ns->trans - last_trans) / delta; |
|
|
186 |
curtmp = 0; |
187 |
// get an average |
188 |
for (i=0;i<info.net_rec_avg_samples;i++) |
189 |
curtmp += net_rec[i]; |
190 |
ns->recv_speed = curtmp / (double)info.net_rec_avg_samples; |
191 |
curtmp = 0; |
192 |
for (i=0;i<info.net_trans_avg_samples;i++) |
193 |
curtmp += net_trans[i]; |
194 |
ns->trans_speed = curtmp / (double)info.net_trans_avg_samples; |
195 |
if (info.net_rec_avg_samples > 1) { |
196 |
for (i=info.net_rec_avg_samples;i>1;i--) |
197 |
net_rec[i-1] = net_rec[i-2]; |
198 |
} |
199 |
if (info.net_trans_avg_samples > 1) { |
200 |
for (i=info.net_trans_avg_samples;i>1;i--) |
201 |
net_trans[i-1] = net_trans[i-2]; |
202 |
} |
203 |
//printf("net %i %i\n", info.net_trans_avg_samples, info.net_rec_avg_samples); |
204 |
|
205 |
|
180 |
} |
206 |
} |
181 |
|
207 |
|
182 |
/* fclose(net_dev_fp); net_dev_fp = NULL; */ |
208 |
/* fclose(net_dev_fp); net_dev_fp = NULL; */ |
Lines 193-200
Link Here
|
193 |
static FILE *stat_fp; |
219 |
static FILE *stat_fp; |
194 |
|
220 |
|
195 |
static void update_stat() { |
221 |
static void update_stat() { |
|
|
222 |
// FIXME: arbitrary size? |
223 |
static double cpu_val[15]; |
196 |
static int rep; |
224 |
static int rep; |
197 |
char buf[256]; |
225 |
char buf[256]; |
|
|
226 |
int i; |
227 |
double curtmp; |
198 |
|
228 |
|
199 |
if (stat_fp == NULL) |
229 |
if (stat_fp == NULL) |
200 |
stat_fp = open_file("/proc/stat", &rep); |
230 |
stat_fp = open_file("/proc/stat", &rep); |
Lines 228-237
Link Here
|
228 |
|
258 |
|
229 |
if (clock_ticks == 0) |
259 |
if (clock_ticks == 0) |
230 |
clock_ticks = sysconf(_SC_CLK_TCK); |
260 |
clock_ticks = sysconf(_SC_CLK_TCK); |
231 |
|
261 |
curtmp = 0; |
232 |
info.cpu_usage = (cpu_user+cpu_nice+cpu_system - last_cpu_sum) / delta |
262 |
cpu_val[0] = (cpu_user+cpu_nice+cpu_system-last_cpu_sum) / delta / (double) clock_ticks / info.cpu_count; |
233 |
/ (double) clock_ticks / info.cpu_count; |
263 |
for (i=0;i<info.cpu_avg_samples;i++) |
|
|
264 |
curtmp += cpu_val[i]; |
265 |
info.cpu_usage = curtmp / info.cpu_avg_samples; |
234 |
last_cpu_sum = cpu_user+cpu_nice+cpu_system; |
266 |
last_cpu_sum = cpu_user+cpu_nice+cpu_system; |
|
|
267 |
for (i=info.cpu_avg_samples;i>1;i--) |
268 |
cpu_val[i-1] = cpu_val[i-2]; |
269 |
//printf("cpu %i\n", info.cpu_avg_samples); |
270 |
|
235 |
} |
271 |
} |
236 |
} |
272 |
} |
237 |
|
273 |
|