aboutsummaryrefslogtreecommitdiff
path: root/procps/top.c
diff options
context:
space:
mode:
authorvda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277>2007-04-19 14:47:11 +0000
committervda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277>2007-04-19 14:47:11 +0000
commit69cd02d7c2af49a10aa412f2666e76d2a1d4234a (patch)
treedd38275bbe7988a0d2c8a806ea51c99e326fa772 /procps/top.c
parentcff0c40a676337eb85bc57589bfe3436a9d21613 (diff)
downloadbusybox-w32-69cd02d7c2af49a10aa412f2666e76d2a1d4234a.tar.gz
busybox-w32-69cd02d7c2af49a10aa412f2666e76d2a1d4234a.tar.bz2
busybox-w32-69cd02d7c2af49a10aa412f2666e76d2a1d4234a.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 git-svn-id: svn://busybox.net/trunk/busybox@18497 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'procps/top.c')
-rw-r--r--procps/top.c77
1 files changed, 48 insertions, 29 deletions
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
34typedef struct { 34typedef 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;
45static top_status_t *top; 45
46static int ntop; 46typedef 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. */
49struct save_hist { 54typedef struct save_hist {
50 unsigned long ticks; 55 unsigned long ticks;
51 unsigned pid; 56 unsigned pid;
57} save_hist;
58
59typedef int (*cmp_funcp)(top_status_t *P, top_status_t *Q);
60
61enum { SORT_DEPTH = 3 };
62
63struct 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
54static struct save_hist *prev_hist; 89#define prev_hist (G.prev_hist )
55static int prev_hist_count; 90#define prev_hist_count (G.prev_hist_count )
56/* static int hist_iterations; */ 91#define jif (G.jif )
57static 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
64static int pid_sort(top_status_t *P, top_status_t *Q) 100static 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
80typedef 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
84static cmp_funcp sort_function;
85
86#else
87
88enum { SORT_DEPTH = 3 };
89
90static cmp_funcp sort_function[SORT_DEPTH];
91 117
92static int pcpu_sort(top_status_t *P, top_status_t *Q) 118static 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
119typedef 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;
124static jiffy_counts_t jif, prev_jif;
125static void get_jiffy_counts(void) 145static 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
394static struct termios initial_settings;
395
396static void reset_term(void) 414static 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