aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2017-08-16 11:40:10 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2017-08-16 11:40:10 +0200
commitd80302db999d8cb92530333801e05652060177c4 (patch)
treefd762f78d658f1f4676bcb2908c2c30678e3634c
parent9832bbaba966f0e52e183f10cd93fad7f8f643fe (diff)
downloadbusybox-w32-d80302db999d8cb92530333801e05652060177c4.tar.gz
busybox-w32-d80302db999d8cb92530333801e05652060177c4.tar.bz2
busybox-w32-d80302db999d8cb92530333801e05652060177c4.zip
top: switch to malloced "globals".
This seems to be more efficient: function old new delta clearmems - 28 +28 display_process_list 1001 1018 +17 read_cpu_jiffy 171 177 +6 do_stats 194 198 +4 reset_term 20 23 +3 topmem_sort 63 65 +2 mult_lvl_cmp 44 45 +1 get_jiffy_counts 247 248 +1 display_topmem_process_list 549 546 -3 top_main 912 879 -33 handle_input 630 549 -81 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 7/3 up/down: 62/-117) Total: -55 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--procps/top.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/procps/top.c b/procps/top.c
index 1bc432fc9..b9958afa0 100644
--- a/procps/top.c
+++ b/procps/top.c
@@ -116,7 +116,6 @@
116//kbuild:lib-$(CONFIG_TOP) += top.o 116//kbuild:lib-$(CONFIG_TOP) += top.o
117 117
118#include "libbb.h" 118#include "libbb.h"
119#include "common_bufsiz.h"
120 119
121 120
122typedef struct top_status_t { 121typedef struct top_status_t {
@@ -154,6 +153,8 @@ typedef int (*cmp_funcp)(top_status_t *P, top_status_t *Q);
154 153
155enum { SORT_DEPTH = 3 }; 154enum { SORT_DEPTH = 3 };
156 155
156/* Screens wider than this are unlikely */
157enum { LINE_BUF_SIZE = 512 - 64 };
157 158
158struct globals { 159struct globals {
159 top_status_t *top; 160 top_status_t *top;
@@ -192,10 +193,9 @@ struct globals {
192#if ENABLE_FEATURE_TOP_INTERACTIVE 193#if ENABLE_FEATURE_TOP_INTERACTIVE
193 char kbd_input[KEYCODE_BUFFER_SIZE]; 194 char kbd_input[KEYCODE_BUFFER_SIZE];
194#endif 195#endif
195 char line_buf[80]; 196 char line_buf[LINE_BUF_SIZE];
196}; //FIX_ALIASING; - large code growth 197};
197enum { LINE_BUF_SIZE = COMMON_BUFSIZE - offsetof(struct globals, line_buf) }; 198#define G (*ptr_to_globals)
198#define G (*(struct globals*)bb_common_bufsiz1)
199#define top (G.top ) 199#define top (G.top )
200#define ntop (G.ntop ) 200#define ntop (G.ntop )
201#define sort_field (G.sort_field ) 201#define sort_field (G.sort_field )
@@ -213,8 +213,7 @@ enum { LINE_BUF_SIZE = COMMON_BUFSIZE - offsetof(struct globals, line_buf) };
213#define total_pcpu (G.total_pcpu ) 213#define total_pcpu (G.total_pcpu )
214#define line_buf (G.line_buf ) 214#define line_buf (G.line_buf )
215#define INIT_G() do { \ 215#define INIT_G() do { \
216 setup_common_bufsiz(); \ 216 SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \
217 BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \
218 BUILD_BUG_ON(LINE_BUF_SIZE <= 80); \ 217 BUILD_BUG_ON(LINE_BUF_SIZE <= 80); \
219} while (0) 218} while (0)
220 219