File src/io.c changed (mode: 100644) (index 1e511bc..ee5f20c) |
... |
... |
enum { |
27 |
27 |
VIEW_PROCESS |
VIEW_PROCESS |
28 |
28 |
}; |
}; |
29 |
29 |
|
|
|
30 |
|
typedef enum { |
|
31 |
|
UNSORTED = 0, |
|
32 |
|
ASCENDING = 1, |
|
33 |
|
DESCENDING = -1 |
|
34 |
|
} sort_t; |
|
35 |
|
|
|
36 |
|
struct column { |
|
37 |
|
/** The column's caption */ |
|
38 |
|
const char* name; |
|
39 |
|
/** Format string for column content*/ |
|
40 |
|
const char* format; |
|
41 |
|
/** Width of the column, in characters. 0 = auto, -1 = hidden */ |
|
42 |
|
int width; |
|
43 |
|
/** Column's sorting order */ |
|
44 |
|
sort_t sorted; |
|
45 |
|
}; |
|
46 |
|
|
|
47 |
|
static struct column columns[] = |
|
48 |
|
{ |
|
49 |
|
{ "PID", "%7ld", 7, UNSORTED}, |
|
50 |
|
{ "rbytes", "%7s", 7, UNSORTED}, |
|
51 |
|
{ "wbytes", "%7s", 7, UNSORTED}, |
|
52 |
|
{ "rspeed", "%7s", 7, DESCENDING}, |
|
53 |
|
{ "wspeed", "%7s", 7, UNSORTED}, |
|
54 |
|
{ "Process", " %s", 0, UNSORTED} |
|
55 |
|
}; |
|
56 |
|
|
|
57 |
|
static const int column_count = 6; |
30 |
58 |
|
|
31 |
59 |
/* Variables */ |
/* Variables */ |
32 |
60 |
static int max_line_len; |
static int max_line_len; |
|
... |
... |
static int cells = 0; |
36 |
64 |
static int selected_line = 0, last_line = 0, useful_lines = 0; |
static int selected_line = 0, last_line = 0, useful_lines = 0; |
37 |
65 |
static int max_pages = 1, page = 0; |
static int max_pages = 1, page = 0; |
38 |
66 |
static pid_t selected_pid = 0; |
static pid_t selected_pid = 0; |
|
67 |
|
unsigned int inverse = 0; |
39 |
68 |
|
|
40 |
69 |
|
|
41 |
70 |
/* Functions */ |
/* Functions */ |
|
... |
... |
static void iotop_show_help(void) |
133 |
162 |
nodelay(stdscr, TRUE); |
nodelay(stdscr, TRUE); |
134 |
163 |
} |
} |
135 |
164 |
|
|
|
165 |
|
/** |
|
166 |
|
* Sort by a column. |
|
167 |
|
* \param column_index the column to sort by |
|
168 |
|
*/ |
|
169 |
|
static void iotop_sort_by_column(int column_index) |
|
170 |
|
{ |
|
171 |
|
int index; |
|
172 |
|
|
|
173 |
|
for(index = 0; index < column_count; index++) { |
|
174 |
|
columns[index].sorted = UNSORTED; |
|
175 |
|
} |
|
176 |
|
if(inverse == 0) { |
|
177 |
|
columns[column_index].sorted = DESCENDING; |
|
178 |
|
} else { |
|
179 |
|
columns[column_index].sorted = ASCENDING; |
|
180 |
|
} |
|
181 |
|
} |
|
182 |
|
|
|
183 |
|
/** |
|
184 |
|
* Reverse sort order. |
|
185 |
|
*/ |
|
186 |
|
static void iotop_sort_reverse(void) |
|
187 |
|
{ |
|
188 |
|
int index; |
|
189 |
|
|
|
190 |
|
for(index = 0; index < column_count; index++) { |
|
191 |
|
/* ASCENDING <--> DESCENDING */ |
|
192 |
|
columns[index].sorted *= (-1); |
|
193 |
|
} |
|
194 |
|
} |
|
195 |
|
|
|
196 |
|
/** |
|
197 |
|
* Print the header for the cells view. |
|
198 |
|
*/ |
|
199 |
|
static void iotop_show_cells_header(void) |
|
200 |
|
{ |
|
201 |
|
int index; |
|
202 |
|
char caption[128]; |
|
203 |
|
char caption_format[8]; |
|
204 |
|
int len; /* the visible length of a column caption */ |
|
205 |
|
int pos; |
|
206 |
|
|
|
207 |
|
/* Background */ |
|
208 |
|
attron(COLOR_PAIR(3)); |
|
209 |
|
iotop_full_line(1, ""); |
|
210 |
|
|
|
211 |
|
pos = 0; |
|
212 |
|
for(index = 0; index < column_count; index++) { |
|
213 |
|
int w = columns[index].width; |
|
214 |
|
switch(w) { |
|
215 |
|
case 0: /* auto */ |
|
216 |
|
sprintf(caption_format, " %%s"); |
|
217 |
|
len = 128; |
|
218 |
|
break; |
|
219 |
|
case -1: /* hidden */ |
|
220 |
|
/* do not write anything */ |
|
221 |
|
len = 0; |
|
222 |
|
break; |
|
223 |
|
default: |
|
224 |
|
sprintf(caption_format, "%%%ds", w); |
|
225 |
|
len = w; |
|
226 |
|
} |
|
227 |
|
snprintf(caption, len + 1, caption_format, columns[index].name); |
|
228 |
|
switch(columns[index].sorted) { |
|
229 |
|
case DESCENDING: |
|
230 |
|
attron(COLOR_PAIR(5)); |
|
231 |
|
break; |
|
232 |
|
case ASCENDING: |
|
233 |
|
attron(COLOR_PAIR(6)); |
|
234 |
|
break; |
|
235 |
|
case UNSORTED: |
|
236 |
|
default: |
|
237 |
|
attron(COLOR_PAIR(3)); |
|
238 |
|
} |
|
239 |
|
mvaddstr(1, pos, caption); |
|
240 |
|
pos += len; |
|
241 |
|
} |
|
242 |
|
} |
|
243 |
|
|
136 |
244 |
/* |
/* |
137 |
245 |
* Picture the entries |
* Picture the entries |
138 |
246 |
*/ |
*/ |
|
... |
... |
static void iotop_show_cells(const unsigned int page, |
145 |
253 |
int line, skip, max; |
int line, skip, max; |
146 |
254 |
char rb[16], wb[16]; |
char rb[16], wb[16]; |
147 |
255 |
char rs[16], ws[16]; |
char rs[16], ws[16]; |
|
256 |
|
char format[256]; |
|
257 |
|
int index; |
148 |
258 |
|
|
149 |
259 |
buf_len = sizeof(buf); |
buf_len = sizeof(buf); |
150 |
260 |
|
|
|
... |
... |
static void iotop_show_cells(const unsigned int page, |
170 |
280 |
pwatch_nice_output(rs, sizeof(rs), p->speed_read); |
pwatch_nice_output(rs, sizeof(rs), p->speed_read); |
171 |
281 |
pwatch_nice_output(ws, sizeof(ws), p->speed_write); |
pwatch_nice_output(ws, sizeof(ws), p->speed_write); |
172 |
282 |
|
|
173 |
|
snprintf(buf, max, "%7ld" |
|
174 |
|
"%7s" |
|
175 |
|
"%7s" |
|
176 |
|
"%7s" |
|
177 |
|
"%7s" |
|
178 |
|
" %s", |
|
|
283 |
|
strcpy(format, ""); |
|
284 |
|
for(index = 0; index < column_count; index++) { |
|
285 |
|
strcat(format, columns[index].format); |
|
286 |
|
} |
|
287 |
|
snprintf(buf, max, format, |
179 |
288 |
(long int) p->pid, |
(long int) p->pid, |
180 |
289 |
rb, wb, rs, ws, p->name); |
rb, wb, rs, ws, p->name); |
181 |
290 |
|
|
|
... |
... |
static void iotop_recompute_screen(void) |
316 |
425 |
int main(int argc, char *argv[]) |
int main(int argc, char *argv[]) |
317 |
426 |
{ |
{ |
318 |
427 |
int ch; |
int ch; |
319 |
|
unsigned int sort_by = SORT_BY_SPEED_READ, inverse = 0; |
|
|
428 |
|
unsigned int sort_by = SORT_BY_SPEED_READ; |
320 |
429 |
unsigned int re_sort = 0, force_sort; |
unsigned int re_sort = 0, force_sort; |
321 |
430 |
char s_sort[256]; |
char s_sort[256]; |
322 |
431 |
char status[256]; |
char status[256]; |
|
... |
... |
int main(int argc, char *argv[]) |
362 |
471 |
init_pair(2, COLOR_WHITE, COLOR_BLACK); |
init_pair(2, COLOR_WHITE, COLOR_BLACK); |
363 |
472 |
init_pair(3, COLOR_WHITE, COLOR_RED); |
init_pair(3, COLOR_WHITE, COLOR_RED); |
364 |
473 |
init_pair(4, COLOR_RED, COLOR_WHITE); |
init_pair(4, COLOR_RED, COLOR_WHITE); |
|
474 |
|
init_pair(5, COLOR_WHITE, COLOR_BLUE); |
|
475 |
|
init_pair(6, COLOR_BLACK, COLOR_CYAN); |
365 |
476 |
|
|
366 |
477 |
iotop_warning(); |
iotop_warning(); |
367 |
478 |
|
|
|
... |
... |
int main(int argc, char *argv[]) |
474 |
585 |
re_sort = 0; |
re_sort = 0; |
475 |
586 |
|
|
476 |
587 |
switch (ch) { |
switch (ch) { |
477 |
|
case '0': inverse = 1 - inverse; break; |
|
478 |
|
case '1': sort_by = SORT_BY_BYTES_READ; break; |
|
479 |
|
case '2': sort_by = SORT_BY_BYTES_WRITE; break; |
|
480 |
|
case '3': sort_by = SORT_BY_SPEED_READ; break; |
|
481 |
|
case '4': sort_by = SORT_BY_SPEED_WRITE; break; |
|
|
588 |
|
case '0': |
|
589 |
|
inverse = 1 - inverse; |
|
590 |
|
iotop_sort_reverse(); |
|
591 |
|
break; |
|
592 |
|
case '1': |
|
593 |
|
sort_by = SORT_BY_BYTES_READ; |
|
594 |
|
iotop_sort_by_column(1); |
|
595 |
|
break; |
|
596 |
|
case '2': |
|
597 |
|
sort_by = SORT_BY_BYTES_WRITE; |
|
598 |
|
iotop_sort_by_column(2); |
|
599 |
|
break; |
|
600 |
|
case '3': |
|
601 |
|
sort_by = SORT_BY_SPEED_READ; |
|
602 |
|
iotop_sort_by_column(3); |
|
603 |
|
break; |
|
604 |
|
case '4': |
|
605 |
|
sort_by = SORT_BY_SPEED_WRITE; |
|
606 |
|
iotop_sort_by_column(4); |
|
607 |
|
break; |
482 |
608 |
} |
} |
483 |
609 |
|
|
484 |
610 |
snprintf(s_sort, sizeof(s_sort), "[Sort by: %s]", |
snprintf(s_sort, sizeof(s_sort), "[Sort by: %s]", |
|
... |
... |
int main(int argc, char *argv[]) |
518 |
644 |
/* line 2 header and body */ |
/* line 2 header and body */ |
519 |
645 |
attron(COLOR_PAIR(3)); |
attron(COLOR_PAIR(3)); |
520 |
646 |
if (view == VIEW_NORMAL) { |
if (view == VIEW_NORMAL) { |
521 |
|
snprintf(status, max_line_len, |
|
522 |
|
" PID rbytes wbytes rspeed wspeed Process"); |
|
523 |
|
iotop_full_line(1, status); |
|
|
647 |
|
iotop_show_cells_header(); |
524 |
648 |
iotop_show_cells(page, cells); |
iotop_show_cells(page, cells); |
525 |
649 |
} else if (view == VIEW_PROCESS) { |
} else if (view == VIEW_PROCESS) { |
526 |
650 |
snprintf(status, max_line_len, |
snprintf(status, max_line_len, |