File src/io.c changed (mode: 100644) (index e0b5eea..45e0b2c) |
... |
... |
enum { |
33 |
33 |
static int max_line_len; |
static int max_line_len; |
34 |
34 |
static struct pwatch_proc *head; |
static struct pwatch_proc *head; |
35 |
35 |
static unsigned int view = VIEW_NORMAL; |
static unsigned int view = VIEW_NORMAL; |
36 |
|
static unsigned int selected_line = 1; |
|
|
36 |
|
static unsigned int cells = 0; |
|
37 |
|
static unsigned int selected_line = 0, last_line = 0, useful_lines = 0; |
|
38 |
|
static unsigned int max_pages = 1, page = 0; |
37 |
39 |
static pid_t selected_pid = 0; |
static pid_t selected_pid = 0; |
38 |
40 |
|
|
39 |
41 |
|
|
|
... |
... |
static void iotop_show_cells(const unsigned int page, |
117 |
119 |
{ |
{ |
118 |
120 |
struct pwatch_proc *p; |
struct pwatch_proc *p; |
119 |
121 |
char buf[256]; |
char buf[256]; |
120 |
|
int limit, max, line, skip; |
|
121 |
|
unsigned int no_of_lines; |
|
|
122 |
|
int max, line, skip; |
122 |
123 |
char rb[16], wb[16]; |
char rb[16], wb[16]; |
123 |
124 |
char rs[16], ws[16]; |
char rs[16], ws[16]; |
124 |
125 |
|
|
|
... |
... |
static void iotop_show_cells(const unsigned int page, |
126 |
127 |
if (max > sizeof(buf)) |
if (max > sizeof(buf)) |
127 |
128 |
max = sizeof(buf); |
max = sizeof(buf); |
128 |
129 |
|
|
129 |
|
/* Limit the number of lines we can show */ |
|
130 |
|
limit = LINES - 3; |
|
131 |
|
|
|
132 |
130 |
/* skip is the number of entries we have to skip */ |
/* skip is the number of entries we have to skip */ |
133 |
|
skip = limit * page; |
|
134 |
|
|
|
135 |
|
no_of_lines = cells - skip; |
|
136 |
|
|
|
137 |
|
/* on the last page, we have only partial entries */ |
|
138 |
|
if (selected_line > no_of_lines) |
|
139 |
|
selected_line = no_of_lines; |
|
|
131 |
|
skip = useful_lines * page; |
140 |
132 |
|
|
141 |
133 |
p = head; |
p = head; |
142 |
|
line = 1; |
|
|
134 |
|
line = 0; |
143 |
135 |
while (p) { |
while (p) { |
144 |
136 |
if (skip > 0) { |
if (skip > 0) { |
145 |
137 |
skip--; |
skip--; |
|
... |
... |
static void iotop_show_cells(const unsigned int page, |
168 |
160 |
} else { |
} else { |
169 |
161 |
attron(COLOR_PAIR(2)); |
attron(COLOR_PAIR(2)); |
170 |
162 |
} |
} |
171 |
|
mvaddstr(1 + line, 0, buf); |
|
|
163 |
|
mvaddstr(2 + line, 0, buf); |
172 |
164 |
|
|
173 |
|
limit--; |
|
174 |
|
if (limit == 0) |
|
|
165 |
|
if (line == last_line) |
175 |
166 |
break; |
break; |
176 |
167 |
|
|
177 |
168 |
line++; |
line++; |
|
... |
... |
static void iotop_show_process(void) |
208 |
199 |
attron(COLOR_PAIR(2)); |
attron(COLOR_PAIR(2)); |
209 |
200 |
|
|
210 |
201 |
ifd = proc->fd_head; |
ifd = proc->fd_head; |
211 |
|
line = 1; |
|
|
202 |
|
line = 0; |
212 |
203 |
while (ifd) { |
while (ifd) { |
213 |
|
if (line > lines_per_page) |
|
|
204 |
|
if (line == lines_per_page) |
214 |
205 |
break; |
break; |
215 |
206 |
|
|
216 |
207 |
pwatch_flags(flags, sizeof(flags), ifd->flags); |
pwatch_flags(flags, sizeof(flags), ifd->flags); |
217 |
208 |
|
|
218 |
209 |
snprintf(buf, max, "%5d %16ld %16ld %13s %s", |
snprintf(buf, max, "%5d %16ld %16ld %13s %s", |
219 |
210 |
ifd->fd, ifd->offset, ifd->size, flags, ifd->file); |
ifd->fd, ifd->offset, ifd->size, flags, ifd->file); |
220 |
|
mvaddstr(1 + line, 0, buf); |
|
|
211 |
|
mvaddstr(2 + line, 0, buf); |
221 |
212 |
|
|
222 |
213 |
line++; |
line++; |
223 |
214 |
|
|
|
... |
... |
static void iotop_show_process(void) |
225 |
216 |
} |
} |
226 |
217 |
} |
} |
227 |
218 |
|
|
|
219 |
|
/* |
|
220 |
|
* Recomputes all screen stuff after some changes |
|
221 |
|
*/ |
|
222 |
|
static void iotop_recompute_screen(void) |
|
223 |
|
{ |
|
224 |
|
useful_lines = LINES - 3; |
|
225 |
|
|
|
226 |
|
/* Compute how many pages we have */ |
|
227 |
|
max_pages = (cells + useful_lines - 1) / useful_lines; |
|
228 |
|
|
|
229 |
|
/* Compute last_line */ |
|
230 |
|
if (page < max_pages - 1) |
|
231 |
|
last_line = useful_lines - 1; |
|
232 |
|
else |
|
233 |
|
last_line = (cells - 1) % useful_lines; |
|
234 |
|
|
|
235 |
|
/* If list shrinked, adapt to it */ |
|
236 |
|
if (page > max_pages - 1) |
|
237 |
|
page = max_pages - 1; |
|
238 |
|
if (selected_line > last_line) |
|
239 |
|
selected_line = last_line; |
|
240 |
|
} |
|
241 |
|
|
228 |
242 |
int main(int argc, char *argv[]) |
int main(int argc, char *argv[]) |
229 |
243 |
{ |
{ |
230 |
244 |
int ch, key_pressed; |
int ch, key_pressed; |
|
... |
... |
int main(int argc, char *argv[]) |
239 |
253 |
unsigned int force_exit = 0; |
unsigned int force_exit = 0; |
240 |
254 |
char error[256]; |
char error[256]; |
241 |
255 |
int errcode; |
int errcode; |
242 |
|
unsigned int cells; |
|
243 |
|
unsigned int page = 0, max_pages = 1; |
|
244 |
|
unsigned int last_line; |
|
|
256 |
|
unsigned int force_redraw = 0; |
245 |
257 |
|
|
246 |
258 |
if (pwatch_counters_avail() == -1) { |
if (pwatch_counters_avail() == -1) { |
247 |
259 |
fprintf(stderr, "Counters are not available." |
fprintf(stderr, "Counters are not available." |
|
... |
... |
int main(int argc, char *argv[]) |
295 |
307 |
if (max_line_len > sizeof(status)) |
if (max_line_len > sizeof(status)) |
296 |
308 |
max_line_len = sizeof(status); |
max_line_len = sizeof(status); |
297 |
309 |
|
|
298 |
|
last_line = LINES - 3; |
|
299 |
|
|
|
300 |
310 |
key_pressed = 0; |
key_pressed = 0; |
301 |
311 |
if ((ch = getch()) != ERR) { |
if ((ch = getch()) != ERR) { |
302 |
312 |
key_pressed = 1; |
key_pressed = 1; |
|
... |
... |
int main(int argc, char *argv[]) |
327 |
337 |
case KEY_NPAGE: |
case KEY_NPAGE: |
328 |
338 |
if (page + 1 < max_pages) { |
if (page + 1 < max_pages) { |
329 |
339 |
page++; |
page++; |
330 |
|
selected_line = 1; |
|
|
340 |
|
selected_line = 0; |
331 |
341 |
} |
} |
332 |
342 |
break; |
break; |
333 |
343 |
case KEY_PPAGE: |
case KEY_PPAGE: |
334 |
344 |
if (page > 0) { |
if (page > 0) { |
335 |
345 |
page--; |
page--; |
336 |
|
selected_line = 1; |
|
|
346 |
|
selected_line = 0; |
337 |
347 |
} |
} |
338 |
348 |
break; |
break; |
339 |
349 |
case KEY_HOME: |
case KEY_HOME: |
340 |
350 |
page = 0; |
page = 0; |
341 |
|
selected_line = 1; |
|
|
351 |
|
selected_line = 0; |
342 |
352 |
break; |
break; |
343 |
353 |
case KEY_END: |
case KEY_END: |
344 |
354 |
page = max_pages - 1; |
page = max_pages - 1; |
345 |
|
selected_line = 1; |
|
|
355 |
|
selected_line = 0; |
346 |
356 |
break; |
break; |
347 |
357 |
case KEY_UP: |
case KEY_UP: |
348 |
|
if (selected_line > 1) { |
|
|
358 |
|
if (selected_line > 0) { |
349 |
359 |
selected_line--; |
selected_line--; |
350 |
360 |
} else if (page > 0) { |
} else if (page > 0) { |
351 |
361 |
page--; |
page--; |
352 |
|
selected_line = last_line; |
|
|
362 |
|
selected_line = useful_lines - 1; |
353 |
363 |
} |
} |
354 |
364 |
break; |
break; |
355 |
365 |
case KEY_DOWN: |
case KEY_DOWN: |
356 |
366 |
if (selected_line < last_line) { |
if (selected_line < last_line) { |
357 |
367 |
selected_line++; |
selected_line++; |
358 |
|
} else if (page + 1 < max_pages) { |
|
|
368 |
|
} else if (page < max_pages - 1) { |
359 |
369 |
page++; |
page++; |
360 |
|
selected_line = 1; |
|
|
370 |
|
selected_line = 0; |
361 |
371 |
} |
} |
362 |
372 |
break; |
break; |
363 |
373 |
case 'i': |
case 'i': |
|
... |
... |
int main(int argc, char *argv[]) |
392 |
402 |
} |
} |
393 |
403 |
|
|
394 |
404 |
/* test if is the momment to do the refresh */ |
/* test if is the momment to do the refresh */ |
|
405 |
|
force_redraw = 0; |
395 |
406 |
if ((refresh_count == 0) || (key_pressed == 1)) { |
if ((refresh_count == 0) || (key_pressed == 1)) { |
396 |
407 |
if ((cells = pwatch_proc_load(&head)) < 0) { |
if ((cells = pwatch_proc_load(&head)) < 0) { |
397 |
408 |
snprintf(error, sizeof(error), "Error getting processes info!\n"); |
snprintf(error, sizeof(error), "Error getting processes info!\n"); |
|
... |
... |
int main(int argc, char *argv[]) |
403 |
414 |
|
|
404 |
415 |
pwatch_proc_sort(&head, sort_by, inverse); |
pwatch_proc_sort(&head, sort_by, inverse); |
405 |
416 |
|
|
406 |
|
/* May be wrong here? */ |
|
407 |
|
max_pages = (cells + (LINES - 3) - 1) / (LINES - 3); |
|
|
417 |
|
force_redraw = 1; |
|
418 |
|
} |
|
419 |
|
|
|
420 |
|
iotop_recompute_screen(); |
408 |
421 |
|
|
409 |
|
/* draw */ |
|
|
422 |
|
if (force_redraw == 1) { |
410 |
423 |
erase(); |
erase(); |
411 |
424 |
|
|
412 |
425 |
/* up status */ |
/* up status */ |