diff options
Diffstat (limited to 'procps')
-rw-r--r-- | procps/top.c | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/procps/top.c b/procps/top.c index 3d67c3cfd..ddf794d7d 100644 --- a/procps/top.c +++ b/procps/top.c | |||
@@ -184,10 +184,6 @@ struct globals { | |||
184 | }; //FIX_ALIASING; - large code growth | 184 | }; //FIX_ALIASING; - large code growth |
185 | enum { LINE_BUF_SIZE = COMMON_BUFSIZE - offsetof(struct globals, line_buf) }; | 185 | enum { LINE_BUF_SIZE = COMMON_BUFSIZE - offsetof(struct globals, line_buf) }; |
186 | #define G (*(struct globals*)&bb_common_bufsiz1) | 186 | #define G (*(struct globals*)&bb_common_bufsiz1) |
187 | struct BUG_bad_size { | ||
188 | char BUG_G_too_big[sizeof(G) <= COMMON_BUFSIZE ? 1 : -1]; | ||
189 | char BUG_line_buf_too_small[LINE_BUF_SIZE > 80 ? 1 : -1]; | ||
190 | }; | ||
191 | #define top (G.top ) | 187 | #define top (G.top ) |
192 | #define ntop (G.ntop ) | 188 | #define ntop (G.ntop ) |
193 | #define sort_field (G.sort_field ) | 189 | #define sort_field (G.sort_field ) |
@@ -204,7 +200,10 @@ struct BUG_bad_size { | |||
204 | #define num_cpus (G.num_cpus ) | 200 | #define num_cpus (G.num_cpus ) |
205 | #define total_pcpu (G.total_pcpu ) | 201 | #define total_pcpu (G.total_pcpu ) |
206 | #define line_buf (G.line_buf ) | 202 | #define line_buf (G.line_buf ) |
207 | #define INIT_G() do { } while (0) | 203 | #define INIT_G() do { \ |
204 | BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \ | ||
205 | BUILD_BUG_ON(LINE_BUF_SIZE <= 80); \ | ||
206 | } while (0) | ||
208 | 207 | ||
209 | enum { | 208 | enum { |
210 | OPT_d = (1 << 0), | 209 | OPT_d = (1 << 0), |
@@ -830,10 +829,17 @@ static NOINLINE void display_topmem_process_list(int lines_rem, int scr_width) | |||
830 | #define HDR_STR " PID VSZ VSZRW RSS (SHR) DIRTY (SHR) STACK" | 829 | #define HDR_STR " PID VSZ VSZRW RSS (SHR) DIRTY (SHR) STACK" |
831 | #define MIN_WIDTH sizeof(HDR_STR) | 830 | #define MIN_WIDTH sizeof(HDR_STR) |
832 | const topmem_status_t *s = topmem + G_scroll_ofs; | 831 | const topmem_status_t *s = topmem + G_scroll_ofs; |
832 | char *cp, ch; | ||
833 | 833 | ||
834 | display_topmem_header(scr_width, &lines_rem); | 834 | display_topmem_header(scr_width, &lines_rem); |
835 | |||
835 | strcpy(line_buf, HDR_STR " COMMAND"); | 836 | strcpy(line_buf, HDR_STR " COMMAND"); |
836 | line_buf[11 + sort_field * 6] = "^_"[inverted]; | 837 | /* Mark the ^FIELD^ we sort by */ |
838 | cp = &line_buf[5 + sort_field * 6]; | ||
839 | ch = "^_"[inverted]; | ||
840 | cp[6] = ch; | ||
841 | do *cp++ = ch; while (*cp == ' '); | ||
842 | |||
837 | printf(OPT_BATCH_MODE ? "%.*s" : "\e[7m%.*s\e[0m", scr_width, line_buf); | 843 | printf(OPT_BATCH_MODE ? "%.*s" : "\e[7m%.*s\e[0m", scr_width, line_buf); |
838 | lines_rem--; | 844 | lines_rem--; |
839 | 845 | ||
@@ -1173,10 +1179,8 @@ int top_main(int argc UNUSED_PARAM, char **argv) | |||
1173 | ntop = 0; | 1179 | ntop = 0; |
1174 | while ((p = procps_scan(p, scan_mask)) != NULL) { | 1180 | while ((p = procps_scan(p, scan_mask)) != NULL) { |
1175 | int n; | 1181 | int n; |
1176 | #if ENABLE_FEATURE_TOPMEM | 1182 | |
1177 | if (scan_mask != TOPMEM_MASK) | 1183 | IF_FEATURE_TOPMEM(if (scan_mask != TOPMEM_MASK)) { |
1178 | #endif | ||
1179 | { | ||
1180 | n = ntop; | 1184 | n = ntop; |
1181 | top = xrealloc_vector(top, 6, ntop++); | 1185 | top = xrealloc_vector(top, 6, ntop++); |
1182 | top[n].pid = p->pid; | 1186 | top[n].pid = p->pid; |
@@ -1216,7 +1220,7 @@ int top_main(int argc UNUSED_PARAM, char **argv) | |||
1216 | break; | 1220 | break; |
1217 | } | 1221 | } |
1218 | 1222 | ||
1219 | if (scan_mask != TOPMEM_MASK) { | 1223 | IF_FEATURE_TOPMEM(if (scan_mask != TOPMEM_MASK)) { |
1220 | #if ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE | 1224 | #if ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE |
1221 | if (!prev_hist_count) { | 1225 | if (!prev_hist_count) { |
1222 | do_stats(); | 1226 | do_stats(); |
@@ -1230,17 +1234,13 @@ int top_main(int argc UNUSED_PARAM, char **argv) | |||
1230 | #else | 1234 | #else |
1231 | qsort(top, ntop, sizeof(top_status_t), (void*)(sort_function[0])); | 1235 | qsort(top, ntop, sizeof(top_status_t), (void*)(sort_function[0])); |
1232 | #endif | 1236 | #endif |
1237 | display_process_list(G.lines, col); | ||
1233 | } | 1238 | } |
1234 | #if ENABLE_FEATURE_TOPMEM | 1239 | #if ENABLE_FEATURE_TOPMEM |
1235 | else { /* TOPMEM */ | 1240 | else { /* TOPMEM */ |
1236 | qsort(topmem, ntop, sizeof(topmem_status_t), (void*)topmem_sort); | 1241 | qsort(topmem, ntop, sizeof(topmem_status_t), (void*)topmem_sort); |
1237 | } | ||
1238 | #endif | ||
1239 | if (scan_mask != TOPMEM_MASK) | ||
1240 | display_process_list(G.lines, col); | ||
1241 | #if ENABLE_FEATURE_TOPMEM | ||
1242 | else | ||
1243 | display_topmem_process_list(G.lines, col); | 1242 | display_topmem_process_list(G.lines, col); |
1243 | } | ||
1244 | #endif | 1244 | #endif |
1245 | clearmems(); | 1245 | clearmems(); |
1246 | if (iterations >= 0 && !--iterations) | 1246 | if (iterations >= 0 && !--iterations) |
@@ -1249,7 +1249,7 @@ int top_main(int argc UNUSED_PARAM, char **argv) | |||
1249 | sleep(interval); | 1249 | sleep(interval); |
1250 | #else | 1250 | #else |
1251 | scan_mask = handle_input(scan_mask, interval); | 1251 | scan_mask = handle_input(scan_mask, interval); |
1252 | #endif /* FEATURE_USE_TERMIOS */ | 1252 | #endif |
1253 | } /* end of "while (not Q)" */ | 1253 | } /* end of "while (not Q)" */ |
1254 | 1254 | ||
1255 | bb_putchar('\n'); | 1255 | bb_putchar('\n'); |