diff options
| author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-04-19 14:47:11 +0000 |
|---|---|---|
| committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-04-19 14:47:11 +0000 |
| commit | 8581863a1b536e2db20036e680b58cc07c54ad55 (patch) | |
| tree | dd38275bbe7988a0d2c8a806ea51c99e326fa772 /procps | |
| parent | 516a0ca2dc92d9ea103535863102cc5425fe648e (diff) | |
| download | busybox-w32-8581863a1b536e2db20036e680b58cc07c54ad55.tar.gz busybox-w32-8581863a1b536e2db20036e680b58cc07c54ad55.tar.bz2 busybox-w32-8581863a1b536e2db20036e680b58cc07c54ad55.zip | |
procps: remove all global variables
text data bss dec hex filename
1462 14 24 1500 5dc busybox.t2/procps/ps.o
1484 0 0 1484 5cc busybox.t3/procps/ps.o
3122 0 252 3374 d2e busybox.t1/procps/top.o
3117 0 0 3117 c2d busybox.t3/procps/top.o
Diffstat (limited to 'procps')
| -rw-r--r-- | procps/ps.c | 36 | ||||
| -rw-r--r-- | procps/top.c | 77 |
2 files changed, 72 insertions, 41 deletions
diff --git a/procps/ps.c b/procps/ps.c index 0c9b71e09..5128c3d59 100644 --- a/procps/ps.c +++ b/procps/ps.c | |||
| @@ -109,7 +109,7 @@ static const ps_out_t out_spec[] = { | |||
| 109 | // { sizeof("RGROUP" )-1, "rgroup","RGROUP" ,func_rgroup,PSSCAN_UIDGID }, | 109 | // { sizeof("RGROUP" )-1, "rgroup","RGROUP" ,func_rgroup,PSSCAN_UIDGID }, |
| 110 | // { sizeof("RUSER" )-1, "ruser" ,"RUSER" ,func_ruser ,PSSCAN_UIDGID }, | 110 | // { sizeof("RUSER" )-1, "ruser" ,"RUSER" ,func_ruser ,PSSCAN_UIDGID }, |
| 111 | // { sizeof("TIME" )-1, "time" ,"TIME" ,func_time ,PSSCAN_ }, | 111 | // { sizeof("TIME" )-1, "time" ,"TIME" ,func_time ,PSSCAN_ }, |
| 112 | { sizeof("TT" )-1, "tty" ,"TT" ,func_tty ,PSSCAN_TTY }, | 112 | { 6 , "tty" ,"TT" ,func_tty ,PSSCAN_TTY }, |
| 113 | { 4 , "vsz" ,"VSZ" ,func_vsz ,PSSCAN_VSZ }, | 113 | { 4 , "vsz" ,"VSZ" ,func_vsz ,PSSCAN_VSZ }, |
| 114 | // Not mandated by POSIX, but useful: | 114 | // Not mandated by POSIX, but useful: |
| 115 | { 4 , "rss" ,"RSS" ,func_rss ,PSSCAN_RSS }, | 115 | { 4 , "rss" ,"RSS" ,func_rss ,PSSCAN_RSS }, |
| @@ -117,13 +117,25 @@ static const ps_out_t out_spec[] = { | |||
| 117 | 117 | ||
| 118 | #define VEC_SIZE(v) ( sizeof(v) / sizeof((v)[0]) ) | 118 | #define VEC_SIZE(v) ( sizeof(v) / sizeof((v)[0]) ) |
| 119 | 119 | ||
| 120 | static ps_out_t* out; | 120 | #define DEFAULT_O_STR "pid,user" /* TODO: ,vsz,stat */ ",args" |
| 121 | static int out_cnt; | ||
| 122 | static int print_header; | ||
| 123 | static int ps_flags; | ||
| 124 | static char *buffer; | ||
| 125 | static unsigned terminal_width; | ||
| 126 | 121 | ||
| 122 | struct globals { | ||
| 123 | ps_out_t* out; | ||
| 124 | int out_cnt; | ||
| 125 | int print_header; | ||
| 126 | int need_flags; | ||
| 127 | char *buffer; | ||
| 128 | unsigned terminal_width; | ||
| 129 | char default_o[sizeof(DEFAULT_O_STR)]; | ||
| 130 | }; | ||
| 131 | #define G (*(struct globals*)&bb_common_bufsiz1) | ||
| 132 | #define out (G.out ) | ||
| 133 | #define out_cnt (G.out_cnt ) | ||
| 134 | #define print_header (G.print_header ) | ||
| 135 | #define need_flags (G.need_flags ) | ||
| 136 | #define buffer (G.buffer ) | ||
| 137 | #define terminal_width (G.terminal_width) | ||
| 138 | #define default_o (G.default_o ) | ||
| 127 | 139 | ||
| 128 | static ps_out_t* new_out_t(void) | 140 | static ps_out_t* new_out_t(void) |
| 129 | { | 141 | { |
| @@ -186,7 +198,7 @@ static void post_process(void) | |||
| 186 | int i; | 198 | int i; |
| 187 | int width = 0; | 199 | int width = 0; |
| 188 | for (i = 0; i < out_cnt; i++) { | 200 | for (i = 0; i < out_cnt; i++) { |
| 189 | ps_flags |= out[i].ps_flags; | 201 | need_flags |= out[i].ps_flags; |
| 190 | if (out[i].header[0]) { | 202 | if (out[i].header[0]) { |
| 191 | print_header = 1; | 203 | print_header = 1; |
| 192 | } | 204 | } |
| @@ -241,15 +253,15 @@ static void format_process(const procps_status_t *ps) | |||
| 241 | printf("%.*s\n", terminal_width, buffer); | 253 | printf("%.*s\n", terminal_width, buffer); |
| 242 | } | 254 | } |
| 243 | 255 | ||
| 244 | /* Cannot be const: parse_o() will choke */ | ||
| 245 | static char default_o[] = "pid,user" /* TODO: ,vsz,stat */ ",args"; | ||
| 246 | |||
| 247 | int ps_main(int argc, char **argv); | 256 | int ps_main(int argc, char **argv); |
| 248 | int ps_main(int argc, char **argv) | 257 | int ps_main(int argc, char **argv) |
| 249 | { | 258 | { |
| 250 | procps_status_t *p; | 259 | procps_status_t *p; |
| 251 | llist_t* opt_o = NULL; | 260 | llist_t* opt_o = NULL; |
| 252 | 261 | ||
| 262 | /* Cannot be const: parse_o() will choke */ | ||
| 263 | strcpy(default_o, DEFAULT_O_STR); | ||
| 264 | |||
| 253 | // POSIX: | 265 | // POSIX: |
| 254 | // -a Write information for all processes associated with terminals | 266 | // -a Write information for all processes associated with terminals |
| 255 | // Implementations may omit session leaders from this list | 267 | // Implementations may omit session leaders from this list |
| @@ -282,7 +294,7 @@ int ps_main(int argc, char **argv) | |||
| 282 | format_header(); | 294 | format_header(); |
| 283 | 295 | ||
| 284 | p = NULL; | 296 | p = NULL; |
| 285 | while ((p = procps_scan(p, ps_flags))) { | 297 | while ((p = procps_scan(p, need_flags))) { |
| 286 | format_process(p); | 298 | format_process(p); |
| 287 | } | 299 | } |
| 288 | 300 | ||
diff --git a/procps/top.c b/procps/top.c index 7d30936a8..580c30050 100644 --- a/procps/top.c +++ b/procps/top.c | |||
| @@ -31,7 +31,7 @@ | |||
| 31 | #include "busybox.h" | 31 | #include "busybox.h" |
| 32 | 32 | ||
| 33 | 33 | ||
| 34 | typedef struct { | 34 | typedef struct top_status_t { |
| 35 | unsigned long vsz; | 35 | unsigned long vsz; |
| 36 | #if ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE | 36 | #if ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE |
| 37 | unsigned long ticks; | 37 | unsigned long ticks; |
| @@ -42,24 +42,60 @@ typedef struct { | |||
| 42 | char state[4]; | 42 | char state[4]; |
| 43 | char comm[COMM_LEN]; | 43 | char comm[COMM_LEN]; |
| 44 | } top_status_t; | 44 | } top_status_t; |
| 45 | static top_status_t *top; | 45 | |
| 46 | static int ntop; | 46 | typedef struct jiffy_counts_t{ |
| 47 | unsigned long long usr,nic,sys,idle,iowait,irq,softirq,steal; | ||
| 48 | unsigned long long total; | ||
| 49 | unsigned long long busy; | ||
| 50 | } jiffy_counts_t; | ||
| 51 | |||
| 47 | /* This structure stores some critical information from one frame to | 52 | /* This structure stores some critical information from one frame to |
| 48 | the next. Used for finding deltas. */ | 53 | the next. Used for finding deltas. */ |
| 49 | struct save_hist { | 54 | typedef struct save_hist { |
| 50 | unsigned long ticks; | 55 | unsigned long ticks; |
| 51 | unsigned pid; | 56 | unsigned pid; |
| 57 | } save_hist; | ||
| 58 | |||
| 59 | typedef int (*cmp_funcp)(top_status_t *P, top_status_t *Q); | ||
| 60 | |||
| 61 | enum { SORT_DEPTH = 3 }; | ||
| 62 | |||
| 63 | struct globals { | ||
| 64 | top_status_t *top; | ||
| 65 | int ntop; | ||
| 66 | #if ENABLE_FEATURE_USE_TERMIOS | ||
| 67 | struct termios initial_settings; | ||
| 68 | #endif | ||
| 69 | #if !ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE | ||
| 70 | cmp_funcp sort_function; | ||
| 71 | #else | ||
| 72 | cmp_funcp sort_function[SORT_DEPTH]; | ||
| 73 | struct save_hist *prev_hist; | ||
| 74 | int prev_hist_count; | ||
| 75 | jiffy_counts_t jif, prev_jif; | ||
| 76 | /* int hist_iterations; */ | ||
| 77 | unsigned total_pcpu; | ||
| 78 | /* unsigned long total_vsz; */ | ||
| 79 | #endif | ||
| 52 | }; | 80 | }; |
| 81 | #define G (*(struct globals*)&bb_common_bufsiz1) | ||
| 82 | #define top (G.top ) | ||
| 83 | #define ntop (G.ntop ) | ||
| 84 | #if ENABLE_FEATURE_USE_TERMIOS | ||
| 85 | #define initial_settings (G. initial_settings ) | ||
| 86 | #endif | ||
| 87 | #define sort_function (G.sort_function ) | ||
| 53 | #if ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE | 88 | #if ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE |
| 54 | static struct save_hist *prev_hist; | 89 | #define prev_hist (G.prev_hist ) |
| 55 | static int prev_hist_count; | 90 | #define prev_hist_count (G.prev_hist_count ) |
| 56 | /* static int hist_iterations; */ | 91 | #define jif (G.jif ) |
| 57 | static unsigned total_pcpu; | 92 | #define prev_jif (G.prev_jif ) |
| 58 | /* static unsigned long total_vsz; */ | 93 | #define total_pcpu (G.total_pcpu ) |
| 59 | #endif | 94 | #endif |
| 60 | 95 | ||
| 61 | #define OPT_BATCH_MODE (option_mask32 & 0x4) | 96 | #define OPT_BATCH_MODE (option_mask32 & 0x4) |
| 62 | 97 | ||
| 98 | |||
| 63 | #if ENABLE_FEATURE_USE_TERMIOS | 99 | #if ENABLE_FEATURE_USE_TERMIOS |
| 64 | static int pid_sort(top_status_t *P, top_status_t *Q) | 100 | static int pid_sort(top_status_t *P, top_status_t *Q) |
| 65 | { | 101 | { |
| @@ -77,17 +113,7 @@ static int mem_sort(top_status_t *P, top_status_t *Q) | |||
| 77 | } | 113 | } |
| 78 | 114 | ||
| 79 | 115 | ||
| 80 | typedef int (*cmp_funcp)(top_status_t *P, top_status_t *Q); | 116 | #if ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE |
| 81 | |||
| 82 | #if !ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE | ||
| 83 | |||
| 84 | static cmp_funcp sort_function; | ||
| 85 | |||
| 86 | #else | ||
| 87 | |||
| 88 | enum { SORT_DEPTH = 3 }; | ||
| 89 | |||
| 90 | static cmp_funcp sort_function[SORT_DEPTH]; | ||
| 91 | 117 | ||
| 92 | static int pcpu_sort(top_status_t *P, top_status_t *Q) | 118 | static int pcpu_sort(top_status_t *P, top_status_t *Q) |
| 93 | { | 119 | { |
| @@ -116,12 +142,6 @@ static int mult_lvl_cmp(void* a, void* b) | |||
| 116 | } | 142 | } |
| 117 | 143 | ||
| 118 | 144 | ||
| 119 | typedef struct { | ||
| 120 | unsigned long long usr,nic,sys,idle,iowait,irq,softirq,steal; | ||
| 121 | unsigned long long total; | ||
| 122 | unsigned long long busy; | ||
| 123 | } jiffy_counts_t; | ||
| 124 | static jiffy_counts_t jif, prev_jif; | ||
| 125 | static void get_jiffy_counts(void) | 145 | static void get_jiffy_counts(void) |
| 126 | { | 146 | { |
| 127 | FILE* fp = xfopen("stat", "r"); | 147 | FILE* fp = xfopen("stat", "r"); |
| @@ -391,8 +411,6 @@ static void clearmems(void) | |||
| 391 | #include <termios.h> | 411 | #include <termios.h> |
| 392 | #include <signal.h> | 412 | #include <signal.h> |
| 393 | 413 | ||
| 394 | static struct termios initial_settings; | ||
| 395 | |||
| 396 | static void reset_term(void) | 414 | static void reset_term(void) |
| 397 | { | 415 | { |
| 398 | tcsetattr(0, TCSANOW, (void *) &initial_settings); | 416 | tcsetattr(0, TCSANOW, (void *) &initial_settings); |
| @@ -426,8 +444,9 @@ int top_main(int argc, char **argv) | |||
| 426 | unsigned char c; | 444 | unsigned char c; |
| 427 | #endif /* FEATURE_USE_TERMIOS */ | 445 | #endif /* FEATURE_USE_TERMIOS */ |
| 428 | 446 | ||
| 429 | /* do normal option parsing */ | ||
| 430 | interval = 5; | 447 | interval = 5; |
| 448 | |||
| 449 | /* do normal option parsing */ | ||
| 431 | opt_complementary = "-"; | 450 | opt_complementary = "-"; |
| 432 | getopt32(argc, argv, "d:n:b", &sinterval, &siterations); | 451 | getopt32(argc, argv, "d:n:b", &sinterval, &siterations); |
| 433 | if (option_mask32 & 0x1) interval = xatou(sinterval); // -d | 452 | if (option_mask32 & 0x1) interval = xatou(sinterval); // -d |
