diff options
Diffstat (limited to 'procps')
-rw-r--r-- | procps/top.c | 44 |
1 files changed, 28 insertions, 16 deletions
diff --git a/procps/top.c b/procps/top.c index b777c494e..075c96c27 100644 --- a/procps/top.c +++ b/procps/top.c | |||
@@ -180,7 +180,7 @@ struct globals { | |||
180 | #else | 180 | #else |
181 | cmp_funcp sort_function[SORT_DEPTH]; | 181 | cmp_funcp sort_function[SORT_DEPTH]; |
182 | struct save_hist *prev_hist; | 182 | struct save_hist *prev_hist; |
183 | int prev_hist_count; | 183 | unsigned prev_hist_count; |
184 | jiffy_counts_t cur_jif, prev_jif; | 184 | jiffy_counts_t cur_jif, prev_jif; |
185 | /* int hist_iterations; */ | 185 | /* int hist_iterations; */ |
186 | unsigned total_pcpu; | 186 | unsigned total_pcpu; |
@@ -189,7 +189,7 @@ struct globals { | |||
189 | #if ENABLE_FEATURE_TOP_SMP_CPU | 189 | #if ENABLE_FEATURE_TOP_SMP_CPU |
190 | /* Per CPU samples: current and last */ | 190 | /* Per CPU samples: current and last */ |
191 | jiffy_counts_t *cpu_jif, *cpu_prev_jif; | 191 | jiffy_counts_t *cpu_jif, *cpu_prev_jif; |
192 | int num_cpus; | 192 | unsigned num_cpus; |
193 | #endif | 193 | #endif |
194 | #if ENABLE_FEATURE_TOP_INTERACTIVE | 194 | #if ENABLE_FEATURE_TOP_INTERACTIVE |
195 | char kbd_input[KEYCODE_BUFFER_SIZE]; | 195 | char kbd_input[KEYCODE_BUFFER_SIZE]; |
@@ -355,7 +355,8 @@ static void do_stats(void) | |||
355 | { | 355 | { |
356 | top_status_t *cur; | 356 | top_status_t *cur; |
357 | pid_t pid; | 357 | pid_t pid; |
358 | int i, last_i, n; | 358 | int n; |
359 | unsigned i, last_i; | ||
359 | struct save_hist *new_hist; | 360 | struct save_hist *new_hist; |
360 | 361 | ||
361 | get_jiffy_counts(); | 362 | get_jiffy_counts(); |
@@ -607,7 +608,6 @@ static NOINLINE void display_process_list(int lines_rem, int scr_width) | |||
607 | }; | 608 | }; |
608 | 609 | ||
609 | top_status_t *s; | 610 | top_status_t *s; |
610 | char vsz_str_buf[8]; | ||
611 | unsigned long total_memory = display_header(scr_width, &lines_rem); /* or use total_vsz? */ | 611 | unsigned long total_memory = display_header(scr_width, &lines_rem); /* or use total_vsz? */ |
612 | /* xxx_shift and xxx_scale variables allow us to replace | 612 | /* xxx_shift and xxx_scale variables allow us to replace |
613 | * expensive divides with multiply and shift */ | 613 | * expensive divides with multiply and shift */ |
@@ -688,19 +688,18 @@ static NOINLINE void display_process_list(int lines_rem, int scr_width) | |||
688 | lines_rem = ntop - G_scroll_ofs; | 688 | lines_rem = ntop - G_scroll_ofs; |
689 | s = top + G_scroll_ofs; | 689 | s = top + G_scroll_ofs; |
690 | while (--lines_rem >= 0) { | 690 | while (--lines_rem >= 0) { |
691 | char vsz_str_buf[8]; | ||
691 | unsigned col; | 692 | unsigned col; |
693 | |||
692 | CALC_STAT(pmem, (s->vsz*pmem_scale + pmem_half) >> pmem_shift); | 694 | CALC_STAT(pmem, (s->vsz*pmem_scale + pmem_half) >> pmem_shift); |
693 | #if ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE | 695 | #if ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE |
694 | CALC_STAT(pcpu, (s->pcpu*pcpu_scale + pcpu_half) >> pcpu_shift); | 696 | CALC_STAT(pcpu, (s->pcpu*pcpu_scale + pcpu_half) >> pcpu_shift); |
695 | #endif | 697 | #endif |
696 | 698 | ||
697 | if (s->vsz >= 100000) | 699 | smart_ulltoa5(s->vsz, vsz_str_buf, " mgtpezy"); |
698 | sprintf(vsz_str_buf, "%6ldm", s->vsz/1024); | ||
699 | else | ||
700 | sprintf(vsz_str_buf, "%7lu", s->vsz); | ||
701 | /* PID PPID USER STAT VSZ %VSZ [%CPU] COMMAND */ | 700 | /* PID PPID USER STAT VSZ %VSZ [%CPU] COMMAND */ |
702 | col = snprintf(line_buf, scr_width, | 701 | col = snprintf(line_buf, scr_width, |
703 | "\n" "%5u%6u %-8.8s %s%s" FMT | 702 | "\n" "%5u%6u %-8.8s %s %.5s" FMT |
704 | IF_FEATURE_TOP_SMP_PROCESS(" %3d") | 703 | IF_FEATURE_TOP_SMP_PROCESS(" %3d") |
705 | IF_FEATURE_TOP_CPU_USAGE_PERCENTAGE(FMT) | 704 | IF_FEATURE_TOP_CPU_USAGE_PERCENTAGE(FMT) |
706 | " ", | 705 | " ", |
@@ -710,7 +709,7 @@ static NOINLINE void display_process_list(int lines_rem, int scr_width) | |||
710 | IF_FEATURE_TOP_SMP_PROCESS(, s->last_seen_on_cpu) | 709 | IF_FEATURE_TOP_SMP_PROCESS(, s->last_seen_on_cpu) |
711 | IF_FEATURE_TOP_CPU_USAGE_PERCENTAGE(, SHOW_STAT(pcpu)) | 710 | IF_FEATURE_TOP_CPU_USAGE_PERCENTAGE(, SHOW_STAT(pcpu)) |
712 | ); | 711 | ); |
713 | if ((int)(col + 1) < scr_width) | 712 | if ((int)(scr_width - col) > 1) |
714 | read_cmdline(line_buf + col, scr_width - col, s->pid, s->comm); | 713 | read_cmdline(line_buf + col, scr_width - col, s->pid, s->comm); |
715 | fputs(line_buf, stdout); | 714 | fputs(line_buf, stdout); |
716 | /* printf(" %d/%d %lld/%lld", s->pcpu, total_pcpu, | 715 | /* printf(" %d/%d %lld/%lld", s->pcpu, total_pcpu, |
@@ -897,7 +896,8 @@ enum { | |||
897 | | PSSCAN_PID | 896 | | PSSCAN_PID |
898 | | PSSCAN_SMAPS | 897 | | PSSCAN_SMAPS |
899 | | PSSCAN_COMM, | 898 | | PSSCAN_COMM, |
900 | EXIT_MASK = (unsigned)-1, | 899 | EXIT_MASK = 0, |
900 | NO_RESCAN_MASK = (unsigned)-1, | ||
901 | }; | 901 | }; |
902 | 902 | ||
903 | #if ENABLE_FEATURE_TOP_INTERACTIVE | 903 | #if ENABLE_FEATURE_TOP_INTERACTIVE |
@@ -935,7 +935,7 @@ static unsigned handle_input(unsigned scan_mask, unsigned interval) | |||
935 | } | 935 | } |
936 | if (c == KEYCODE_HOME) { | 936 | if (c == KEYCODE_HOME) { |
937 | G_scroll_ofs = 0; | 937 | G_scroll_ofs = 0; |
938 | break; | 938 | goto normalize_ofs; |
939 | } | 939 | } |
940 | if (c == KEYCODE_END) { | 940 | if (c == KEYCODE_END) { |
941 | G_scroll_ofs = ntop - G.lines / 2; | 941 | G_scroll_ofs = ntop - G.lines / 2; |
@@ -952,7 +952,7 @@ static unsigned handle_input(unsigned scan_mask, unsigned interval) | |||
952 | G_scroll_ofs = ntop - 1; | 952 | G_scroll_ofs = ntop - 1; |
953 | if (G_scroll_ofs < 0) | 953 | if (G_scroll_ofs < 0) |
954 | G_scroll_ofs = 0; | 954 | G_scroll_ofs = 0; |
955 | break; | 955 | return NO_RESCAN_MASK; |
956 | } | 956 | } |
957 | 957 | ||
958 | c |= 0x20; /* lowercase */ | 958 | c |= 0x20; /* lowercase */ |
@@ -1157,6 +1157,7 @@ int top_main(int argc UNUSED_PARAM, char **argv) | |||
1157 | #endif | 1157 | #endif |
1158 | 1158 | ||
1159 | while (scan_mask != EXIT_MASK) { | 1159 | while (scan_mask != EXIT_MASK) { |
1160 | unsigned new_mask; | ||
1160 | procps_status_t *p = NULL; | 1161 | procps_status_t *p = NULL; |
1161 | 1162 | ||
1162 | if (OPT_BATCH_MODE) { | 1163 | if (OPT_BATCH_MODE) { |
@@ -1234,21 +1235,32 @@ int top_main(int argc UNUSED_PARAM, char **argv) | |||
1234 | #else | 1235 | #else |
1235 | qsort(top, ntop, sizeof(top_status_t), (void*)(sort_function[0])); | 1236 | qsort(top, ntop, sizeof(top_status_t), (void*)(sort_function[0])); |
1236 | #endif | 1237 | #endif |
1237 | display_process_list(G.lines, col); | ||
1238 | } | 1238 | } |
1239 | #if ENABLE_FEATURE_TOPMEM | 1239 | #if ENABLE_FEATURE_TOPMEM |
1240 | else { /* TOPMEM */ | 1240 | else { /* TOPMEM */ |
1241 | qsort(topmem, ntop, sizeof(topmem_status_t), (void*)topmem_sort); | 1241 | qsort(topmem, ntop, sizeof(topmem_status_t), (void*)topmem_sort); |
1242 | } | ||
1243 | #endif | ||
1244 | IF_FEATURE_TOP_INTERACTIVE(display:) | ||
1245 | IF_FEATURE_TOPMEM(if (scan_mask != TOPMEM_MASK)) { | ||
1246 | display_process_list(G.lines, col); | ||
1247 | } | ||
1248 | #if ENABLE_FEATURE_TOPMEM | ||
1249 | else { /* TOPMEM */ | ||
1242 | display_topmem_process_list(G.lines, col); | 1250 | display_topmem_process_list(G.lines, col); |
1243 | } | 1251 | } |
1244 | #endif | 1252 | #endif |
1245 | clearmems(); | ||
1246 | if (iterations >= 0 && !--iterations) | 1253 | if (iterations >= 0 && !--iterations) |
1247 | break; | 1254 | break; |
1248 | #if !ENABLE_FEATURE_TOP_INTERACTIVE | 1255 | #if !ENABLE_FEATURE_TOP_INTERACTIVE |
1256 | clearmems(); | ||
1249 | sleep(interval); | 1257 | sleep(interval); |
1250 | #else | 1258 | #else |
1251 | scan_mask = handle_input(scan_mask, interval); | 1259 | new_mask = handle_input(scan_mask, interval); |
1260 | if (new_mask == NO_RESCAN_MASK) | ||
1261 | goto display; | ||
1262 | scan_mask = new_mask; | ||
1263 | clearmems(); | ||
1252 | #endif | 1264 | #endif |
1253 | } /* end of "while (not Q)" */ | 1265 | } /* end of "while (not Q)" */ |
1254 | 1266 | ||