aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-03-07 04:47:52 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2018-03-07 04:47:52 +0100
commita2cae937d026d70f5014b95498b08251f73d39eb (patch)
tree28a743e515dab5fca103f24697aa49e0814e2dec
parent75e56a3db9c1415dac1a3d83a12f694930897a8c (diff)
downloadbusybox-w32-a2cae937d026d70f5014b95498b08251f73d39eb.tar.gz
busybox-w32-a2cae937d026d70f5014b95498b08251f73d39eb.tar.bz2
busybox-w32-a2cae937d026d70f5014b95498b08251f73d39eb.zip
top: much faster cursor key navigation by avoiding process rescan
function old new delta handle_input 549 560 +11 top_main 889 891 +2 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--procps/top.c25
1 files changed, 19 insertions, 6 deletions
diff --git a/procps/top.c b/procps/top.c
index fc056621b..075c96c27 100644
--- a/procps/top.c
+++ b/procps/top.c
@@ -896,7 +896,8 @@ enum {
896 | PSSCAN_PID 896 | PSSCAN_PID
897 | PSSCAN_SMAPS 897 | PSSCAN_SMAPS
898 | PSSCAN_COMM, 898 | PSSCAN_COMM,
899 EXIT_MASK = (unsigned)-1, 899 EXIT_MASK = 0,
900 NO_RESCAN_MASK = (unsigned)-1,
900}; 901};
901 902
902#if ENABLE_FEATURE_TOP_INTERACTIVE 903#if ENABLE_FEATURE_TOP_INTERACTIVE
@@ -934,7 +935,7 @@ static unsigned handle_input(unsigned scan_mask, unsigned interval)
934 } 935 }
935 if (c == KEYCODE_HOME) { 936 if (c == KEYCODE_HOME) {
936 G_scroll_ofs = 0; 937 G_scroll_ofs = 0;
937 break; 938 goto normalize_ofs;
938 } 939 }
939 if (c == KEYCODE_END) { 940 if (c == KEYCODE_END) {
940 G_scroll_ofs = ntop - G.lines / 2; 941 G_scroll_ofs = ntop - G.lines / 2;
@@ -951,7 +952,7 @@ static unsigned handle_input(unsigned scan_mask, unsigned interval)
951 G_scroll_ofs = ntop - 1; 952 G_scroll_ofs = ntop - 1;
952 if (G_scroll_ofs < 0) 953 if (G_scroll_ofs < 0)
953 G_scroll_ofs = 0; 954 G_scroll_ofs = 0;
954 break; 955 return NO_RESCAN_MASK;
955 } 956 }
956 957
957 c |= 0x20; /* lowercase */ 958 c |= 0x20; /* lowercase */
@@ -1156,6 +1157,7 @@ int top_main(int argc UNUSED_PARAM, char **argv)
1156#endif 1157#endif
1157 1158
1158 while (scan_mask != EXIT_MASK) { 1159 while (scan_mask != EXIT_MASK) {
1160 unsigned new_mask;
1159 procps_status_t *p = NULL; 1161 procps_status_t *p = NULL;
1160 1162
1161 if (OPT_BATCH_MODE) { 1163 if (OPT_BATCH_MODE) {
@@ -1233,21 +1235,32 @@ int top_main(int argc UNUSED_PARAM, char **argv)
1233#else 1235#else
1234 qsort(top, ntop, sizeof(top_status_t), (void*)(sort_function[0])); 1236 qsort(top, ntop, sizeof(top_status_t), (void*)(sort_function[0]));
1235#endif 1237#endif
1236 display_process_list(G.lines, col);
1237 } 1238 }
1238#if ENABLE_FEATURE_TOPMEM 1239#if ENABLE_FEATURE_TOPMEM
1239 else { /* TOPMEM */ 1240 else { /* TOPMEM */
1240 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 */
1241 display_topmem_process_list(G.lines, col); 1250 display_topmem_process_list(G.lines, col);
1242 } 1251 }
1243#endif 1252#endif
1244 clearmems();
1245 if (iterations >= 0 && !--iterations) 1253 if (iterations >= 0 && !--iterations)
1246 break; 1254 break;
1247#if !ENABLE_FEATURE_TOP_INTERACTIVE 1255#if !ENABLE_FEATURE_TOP_INTERACTIVE
1256 clearmems();
1248 sleep(interval); 1257 sleep(interval);
1249#else 1258#else
1250 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();
1251#endif 1264#endif
1252 } /* end of "while (not Q)" */ 1265 } /* end of "while (not Q)" */
1253 1266