diff options
author | vapier <vapier@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2007-02-08 08:21:58 +0000 |
---|---|---|
committer | vapier <vapier@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2007-02-08 08:21:58 +0000 |
commit | 2f011cf6459116975eb15cb85a9d7949c1eba9f4 (patch) | |
tree | 72424e60f565c397b8a2b10f88855f11b46c4010 | |
parent | 69e92e11b82f87b212ce9aa14596042339d0288c (diff) | |
download | busybox-w32-2f011cf6459116975eb15cb85a9d7949c1eba9f4.tar.gz busybox-w32-2f011cf6459116975eb15cb85a9d7949c1eba9f4.tar.bz2 busybox-w32-2f011cf6459116975eb15cb85a9d7949c1eba9f4.zip |
make sure ps/top output what they claim: vsz, not rss ... down the line we should make the output controllable either at runtime or buildtime as both statistics are quite useful
git-svn-id: svn://busybox.net/trunk/busybox@17813 69ca8d6d-28ef-0310-b511-8ec308f3f277
-rw-r--r-- | TODO | 4 | ||||
-rw-r--r-- | include/libbb.h | 6 | ||||
-rw-r--r-- | libbb/procps.c | 16 | ||||
-rw-r--r-- | procps/ps.c | 16 | ||||
-rw-r--r-- | procps/top.c | 42 |
5 files changed, 41 insertions, 43 deletions
@@ -154,6 +154,10 @@ patch | |||
154 | And while we're at it, a new patch filename quoting format is apparently | 154 | And while we're at it, a new patch filename quoting format is apparently |
155 | coming soon: http://marc.theaimsgroup.com/?l=git&m=112927316408690&w=2 | 155 | coming soon: http://marc.theaimsgroup.com/?l=git&m=112927316408690&w=2 |
156 | --- | 156 | --- |
157 | ps / top | ||
158 | Add support for both RSS and VSIZE rather than just one or the other. | ||
159 | Or make it a build option. | ||
160 | --- | ||
157 | man | 161 | man |
158 | It would be nice to have a man command. Not one that handles troff or | 162 | It would be nice to have a man command. Not one that handles troff or |
159 | anything, just one that can handle preformatted ascii man pages, possibly | 163 | anything, just one that can handle preformatted ascii man pages, possibly |
diff --git a/include/libbb.h b/include/libbb.h index 5b2f6251f..bb4a68741 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -668,7 +668,7 @@ typedef struct { | |||
668 | DIR *dir; | 668 | DIR *dir; |
669 | /* Fields are set to 0/NULL if failed to determine (or not requested) */ | 669 | /* Fields are set to 0/NULL if failed to determine (or not requested) */ |
670 | char *cmd; | 670 | char *cmd; |
671 | unsigned long rss; | 671 | unsigned long vsz; |
672 | unsigned long stime, utime; | 672 | unsigned long stime, utime; |
673 | unsigned pid; | 673 | unsigned pid; |
674 | unsigned ppid; | 674 | unsigned ppid; |
@@ -691,13 +691,13 @@ enum { | |||
691 | PSSCAN_COMM = 1 << 5, | 691 | PSSCAN_COMM = 1 << 5, |
692 | PSSCAN_CMD = 1 << 6, | 692 | PSSCAN_CMD = 1 << 6, |
693 | PSSCAN_STATE = 1 << 7, | 693 | PSSCAN_STATE = 1 << 7, |
694 | PSSCAN_RSS = 1 << 8, | 694 | PSSCAN_VSZ = 1 << 8, |
695 | PSSCAN_STIME = 1 << 9, | 695 | PSSCAN_STIME = 1 << 9, |
696 | PSSCAN_UTIME = 1 << 10, | 696 | PSSCAN_UTIME = 1 << 10, |
697 | /* These are all retrieved from proc/NN/stat in one go: */ | 697 | /* These are all retrieved from proc/NN/stat in one go: */ |
698 | PSSCAN_STAT = PSSCAN_PPID | PSSCAN_PGID | PSSCAN_SID | 698 | PSSCAN_STAT = PSSCAN_PPID | PSSCAN_PGID | PSSCAN_SID |
699 | | PSSCAN_COMM | PSSCAN_STATE | 699 | | PSSCAN_COMM | PSSCAN_STATE |
700 | | PSSCAN_RSS | PSSCAN_STIME | PSSCAN_UTIME, | 700 | | PSSCAN_VSZ | PSSCAN_STIME | PSSCAN_UTIME, |
701 | }; | 701 | }; |
702 | procps_status_t* alloc_procps_scan(int flags); | 702 | procps_status_t* alloc_procps_scan(int flags); |
703 | void free_procps_scan(procps_status_t* sp); | 703 | void free_procps_scan(procps_status_t* sp); |
diff --git a/libbb/procps.c b/libbb/procps.c index e7635e5f4..c9dcfde0c 100644 --- a/libbb/procps.c +++ b/libbb/procps.c | |||
@@ -127,7 +127,7 @@ procps_status_t* procps_scan(procps_status_t* sp, int flags) | |||
127 | * ("continue" would mean that current /proc/NNN | 127 | * ("continue" would mean that current /proc/NNN |
128 | * is not a valid process info) */ | 128 | * is not a valid process info) */ |
129 | 129 | ||
130 | memset(&sp->rss, 0, sizeof(*sp) - offsetof(procps_status_t, rss)); | 130 | memset(&sp->vsz, 0, sizeof(*sp) - offsetof(procps_status_t, vsz)); |
131 | 131 | ||
132 | sp->pid = pid; | 132 | sp->pid = pid; |
133 | if (!(flags & ~PSSCAN_PID)) break; | 133 | if (!(flags & ~PSSCAN_PID)) break; |
@@ -164,17 +164,16 @@ procps_status_t* procps_scan(procps_status_t* sp, int flags) | |||
164 | "%*s %*s %*s " /* cutime, cstime, priority */ | 164 | "%*s %*s %*s " /* cutime, cstime, priority */ |
165 | "%ld " /* nice */ | 165 | "%ld " /* nice */ |
166 | "%*s %*s %*s " /* timeout, it_real_value, start_time */ | 166 | "%*s %*s %*s " /* timeout, it_real_value, start_time */ |
167 | "%*s " /* vsize */ | 167 | "%lu ", /* vsize */ |
168 | "%lu", /* rss */ | ||
169 | sp->state, &sp->ppid, | 168 | sp->state, &sp->ppid, |
170 | &sp->pgid, &sp->sid, | 169 | &sp->pgid, &sp->sid, |
171 | &sp->utime, &sp->stime, | 170 | &sp->utime, &sp->stime, |
172 | &tasknice, | 171 | &tasknice, |
173 | &sp->rss); | 172 | &sp->vsz); |
174 | if (n != 8) | 173 | if (n != 8) |
175 | break; | 174 | break; |
176 | 175 | ||
177 | if (sp->rss == 0 && sp->state[0] != 'Z') | 176 | if (sp->vsz == 0 && sp->state[0] != 'Z') |
178 | sp->state[1] = 'W'; | 177 | sp->state[1] = 'W'; |
179 | else | 178 | else |
180 | sp->state[1] = ' '; | 179 | sp->state[1] = ' '; |
@@ -185,11 +184,7 @@ procps_status_t* procps_scan(procps_status_t* sp, int flags) | |||
185 | else | 184 | else |
186 | sp->state[2] = ' '; | 185 | sp->state[2] = ' '; |
187 | 186 | ||
188 | #ifdef PAGE_SHIFT | 187 | sp->vsz >>= 10; /* vsize is in bytes and we want kb */ |
189 | sp->rss <<= (PAGE_SHIFT - 10); /* 2**10 = 1kb */ | ||
190 | #else | ||
191 | sp->rss *= (getpagesize() >> 10); /* 2**10 = 1kb */ | ||
192 | #endif | ||
193 | } | 188 | } |
194 | 189 | ||
195 | if (flags & PSSCAN_CMD) { | 190 | if (flags & PSSCAN_CMD) { |
@@ -230,7 +225,6 @@ procps_status_t* procps_scan(procps_status_t* sp, int flags) | |||
230 | tty_pgrp, | 225 | tty_pgrp, |
231 | task->flags, | 226 | task->flags, |
232 | min_flt, | 227 | min_flt, |
233 | |||
234 | cmin_flt, | 228 | cmin_flt, |
235 | maj_flt, | 229 | maj_flt, |
236 | cmaj_flt, | 230 | cmaj_flt, |
diff --git a/procps/ps.c b/procps/ps.c index f3d11b72c..a9da807a5 100644 --- a/procps/ps.c +++ b/procps/ps.c | |||
@@ -47,10 +47,10 @@ static void func_pgid(char *buf, int size, const procps_status_t *ps) | |||
47 | snprintf(buf, size+1, "%*u", size, ps->pgid); | 47 | snprintf(buf, size+1, "%*u", size, ps->pgid); |
48 | } | 48 | } |
49 | 49 | ||
50 | static void func_rss(char *buf, int size, const procps_status_t *ps) | 50 | static void func_vsz(char *buf, int size, const procps_status_t *ps) |
51 | { | 51 | { |
52 | char buf5[5]; | 52 | char buf5[5]; |
53 | smart_ulltoa5( ((unsigned long long)ps->rss) << 10, buf5); | 53 | smart_ulltoa5( ((unsigned long long)ps->vsz) << 10, buf5); |
54 | snprintf(buf, size+1, "%.*s", size, buf5); | 54 | snprintf(buf, size+1, "%.*s", size, buf5); |
55 | } | 55 | } |
56 | 56 | ||
@@ -103,9 +103,9 @@ static const ps_out_t out_spec[] = { | |||
103 | // { "ruser" ,"RUSER" ,func_ruser ,PSSCAN_UIDGID,sizeof("RUSER" )-1 }, | 103 | // { "ruser" ,"RUSER" ,func_ruser ,PSSCAN_UIDGID,sizeof("RUSER" )-1 }, |
104 | // { "time" ,"TIME" ,func_time ,PSSCAN_ ,sizeof("TIME" )-1 }, | 104 | // { "time" ,"TIME" ,func_time ,PSSCAN_ ,sizeof("TIME" )-1 }, |
105 | // { "tty" ,"TT" ,func_tty ,PSSCAN_ ,sizeof("TT" )-1 }, | 105 | // { "tty" ,"TT" ,func_tty ,PSSCAN_ ,sizeof("TT" )-1 }, |
106 | // { "vsz" ,"VSZ" ,func_vsz ,PSSCAN_VSZ ,4 }, | 106 | { "vsz" ,"VSZ" ,func_vsz ,PSSCAN_VSZ ,4 }, |
107 | // Not mandated by POSIX: | 107 | // Not mandated by POSIX: |
108 | { "rss" ,"RSS" ,func_rss ,PSSCAN_RSS ,4 }, | 108 | // { "rss" ,"RSS" ,func_rss ,PSSCAN_RSS ,4 }, |
109 | }; | 109 | }; |
110 | 110 | ||
111 | #define VEC_SIZE(v) ( sizeof(v) / sizeof((v)[0]) ) | 111 | #define VEC_SIZE(v) ( sizeof(v) / sizeof((v)[0]) ) |
@@ -321,13 +321,13 @@ int ps_main(int argc, char **argv) | |||
321 | if (use_selinux) | 321 | if (use_selinux) |
322 | puts(" PID Context Stat Command"); | 322 | puts(" PID Context Stat Command"); |
323 | else | 323 | else |
324 | puts(" PID Uid VmSize Stat Command"); | 324 | puts(" PID Uid VSZ Stat Command"); |
325 | 325 | ||
326 | while ((p = procps_scan(p, 0 | 326 | while ((p = procps_scan(p, 0 |
327 | | PSSCAN_PID | 327 | | PSSCAN_PID |
328 | | PSSCAN_UIDGID | 328 | | PSSCAN_UIDGID |
329 | | PSSCAN_STATE | 329 | | PSSCAN_STATE |
330 | | PSSCAN_RSS | 330 | | PSSCAN_VSZ |
331 | | PSSCAN_CMD | 331 | | PSSCAN_CMD |
332 | ))) { | 332 | ))) { |
333 | char *namecmd = p->cmd; | 333 | char *namecmd = p->cmd; |
@@ -355,12 +355,12 @@ int ps_main(int argc, char **argv) | |||
355 | #endif | 355 | #endif |
356 | { | 356 | { |
357 | const char *user = get_cached_username(p->uid); | 357 | const char *user = get_cached_username(p->uid); |
358 | if (p->rss == 0) | 358 | if (p->vsz == 0) |
359 | len = printf("%5u %-8s %s ", | 359 | len = printf("%5u %-8s %s ", |
360 | p->pid, user, p->state); | 360 | p->pid, user, p->state); |
361 | else | 361 | else |
362 | len = printf("%5u %-8s %6ld %s ", | 362 | len = printf("%5u %-8s %6ld %s ", |
363 | p->pid, user, p->rss, p->state); | 363 | p->pid, user, p->vsz, p->state); |
364 | } | 364 | } |
365 | 365 | ||
366 | i = terminal_width-len; | 366 | i = terminal_width-len; |
diff --git a/procps/top.c b/procps/top.c index 2681f9748..ee6ee5d5c 100644 --- a/procps/top.c +++ b/procps/top.c | |||
@@ -32,7 +32,7 @@ | |||
32 | 32 | ||
33 | 33 | ||
34 | typedef struct { | 34 | typedef struct { |
35 | unsigned long rss; | 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; |
38 | unsigned pcpu; /* delta of ticks */ | 38 | unsigned pcpu; /* delta of ticks */ |
@@ -55,7 +55,7 @@ static struct save_hist *prev_hist; | |||
55 | static int prev_hist_count; | 55 | static int prev_hist_count; |
56 | /* static int hist_iterations; */ | 56 | /* static int hist_iterations; */ |
57 | static unsigned total_pcpu; | 57 | static unsigned total_pcpu; |
58 | /* static unsigned long total_rss; */ | 58 | /* static unsigned long total_vsz; */ |
59 | #endif | 59 | #endif |
60 | 60 | ||
61 | #define OPT_BATCH_MODE (option_mask32 & 0x4) | 61 | #define OPT_BATCH_MODE (option_mask32 & 0x4) |
@@ -72,8 +72,8 @@ static int pid_sort(top_status_t *P, top_status_t *Q) | |||
72 | static int mem_sort(top_status_t *P, top_status_t *Q) | 72 | static int mem_sort(top_status_t *P, top_status_t *Q) |
73 | { | 73 | { |
74 | /* We want to avoid unsigned->signed and truncation errors */ | 74 | /* We want to avoid unsigned->signed and truncation errors */ |
75 | if (Q->rss < P->rss) return -1; | 75 | if (Q->vsz < P->vsz) return -1; |
76 | return Q->rss != P->rss; /* 0 if ==, 1 if > */ | 76 | return Q->vsz != P->vsz; /* 0 if ==, 1 if > */ |
77 | } | 77 | } |
78 | 78 | ||
79 | 79 | ||
@@ -147,7 +147,7 @@ static void do_stats(void) | |||
147 | 147 | ||
148 | get_jiffy_counts(); | 148 | get_jiffy_counts(); |
149 | total_pcpu = 0; | 149 | total_pcpu = 0; |
150 | /* total_rss = 0; */ | 150 | /* total_vsz = 0; */ |
151 | new_hist = xmalloc(sizeof(struct save_hist)*ntop); | 151 | new_hist = xmalloc(sizeof(struct save_hist)*ntop); |
152 | /* | 152 | /* |
153 | * Make a pass through the data to get stats. | 153 | * Make a pass through the data to get stats. |
@@ -179,7 +179,7 @@ static void do_stats(void) | |||
179 | i = (i+1) % prev_hist_count; | 179 | i = (i+1) % prev_hist_count; |
180 | /* hist_iterations++; */ | 180 | /* hist_iterations++; */ |
181 | } while (i != last_i); | 181 | } while (i != last_i); |
182 | /* total_rss += cur->rss; */ | 182 | /* total_vsz += cur->vsz; */ |
183 | } | 183 | } |
184 | 184 | ||
185 | /* | 185 | /* |
@@ -287,8 +287,8 @@ static void display_status(int count, int scr_width) | |||
287 | }; | 287 | }; |
288 | 288 | ||
289 | top_status_t *s = top; | 289 | top_status_t *s = top; |
290 | char rss_str_buf[8]; | 290 | char vsz_str_buf[8]; |
291 | unsigned long total_memory = display_generic(scr_width); /* or use total_rss? */ | 291 | unsigned long total_memory = display_generic(scr_width); /* or use total_vsz? */ |
292 | unsigned pmem_shift, pmem_scale; | 292 | unsigned pmem_shift, pmem_scale; |
293 | 293 | ||
294 | #if ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE | 294 | #if ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE |
@@ -297,22 +297,22 @@ static void display_status(int count, int scr_width) | |||
297 | 297 | ||
298 | /* what info of the processes is shown */ | 298 | /* what info of the processes is shown */ |
299 | printf(OPT_BATCH_MODE ? "%.*s" : "\e[7m%.*s\e[0m", scr_width, | 299 | printf(OPT_BATCH_MODE ? "%.*s" : "\e[7m%.*s\e[0m", scr_width, |
300 | " PID USER STATUS RSS PPID %CPU %MEM COMMAND"); | 300 | " PID USER STATUS VSZ PPID %CPU %MEM COMMAND"); |
301 | #define MIN_WIDTH \ | 301 | #define MIN_WIDTH \ |
302 | sizeof( " PID USER STATUS RSS PPID %CPU %MEM C") | 302 | sizeof( " PID USER STATUS VSZ PPID %CPU %MEM C") |
303 | #else | 303 | #else |
304 | printf(OPT_BATCH_MODE ? "%.*s" : "\e[7m%.*s\e[0m", scr_width, | 304 | printf(OPT_BATCH_MODE ? "%.*s" : "\e[7m%.*s\e[0m", scr_width, |
305 | " PID USER STATUS RSS PPID %MEM COMMAND"); | 305 | " PID USER STATUS VSZ PPID %MEM COMMAND"); |
306 | #define MIN_WIDTH \ | 306 | #define MIN_WIDTH \ |
307 | sizeof( " PID USER STATUS RSS PPID %MEM C") | 307 | sizeof( " PID USER STATUS VSZ PPID %MEM C") |
308 | #endif | 308 | #endif |
309 | 309 | ||
310 | /* | 310 | /* |
311 | * MEM% = s->rss/MemTotal | 311 | * MEM% = s->vsz/MemTotal |
312 | */ | 312 | */ |
313 | pmem_shift = bits_per_int-11; | 313 | pmem_shift = bits_per_int-11; |
314 | pmem_scale = 1000*(1U<<(bits_per_int-11)) / total_memory; | 314 | pmem_scale = 1000*(1U<<(bits_per_int-11)) / total_memory; |
315 | /* s->rss is in kb. we want (s->rss * pmem_scale) to never overflow */ | 315 | /* s->vsz is in kb. we want (s->vsz * pmem_scale) to never overflow */ |
316 | while (pmem_scale >= 512) { | 316 | while (pmem_scale >= 512) { |
317 | pmem_scale /= 4; | 317 | pmem_scale /= 4; |
318 | pmem_shift -= 2; | 318 | pmem_shift -= 2; |
@@ -346,14 +346,14 @@ static void display_status(int count, int scr_width) | |||
346 | /* printf(" pmem_scale=%u pcpu_scale=%u ", pmem_scale, pcpu_scale); */ | 346 | /* printf(" pmem_scale=%u pcpu_scale=%u ", pmem_scale, pcpu_scale); */ |
347 | #endif | 347 | #endif |
348 | while (count-- > 0) { | 348 | while (count-- > 0) { |
349 | div_t pmem = div((s->rss*pmem_scale) >> pmem_shift, 10); | 349 | div_t pmem = div((s->vsz*pmem_scale) >> pmem_shift, 10); |
350 | int col = scr_width+1; | 350 | int col = scr_width+1; |
351 | USE_FEATURE_TOP_CPU_USAGE_PERCENTAGE(div_t pcpu;) | 351 | USE_FEATURE_TOP_CPU_USAGE_PERCENTAGE(div_t pcpu;) |
352 | 352 | ||
353 | if (s->rss >= 100*1024) | 353 | if (s->vsz >= 100*1024) |
354 | sprintf(rss_str_buf, "%6ldM", s->rss/1024); | 354 | sprintf(vsz_str_buf, "%6ldM", s->vsz/1024); |
355 | else | 355 | else |
356 | sprintf(rss_str_buf, "%7ld", s->rss); | 356 | sprintf(vsz_str_buf, "%7ld", s->vsz); |
357 | USE_FEATURE_TOP_CPU_USAGE_PERCENTAGE( | 357 | USE_FEATURE_TOP_CPU_USAGE_PERCENTAGE( |
358 | pcpu = div((s->pcpu*pcpu_scale) >> pcpu_shift, 10); | 358 | pcpu = div((s->pcpu*pcpu_scale) >> pcpu_shift, 10); |
359 | ) | 359 | ) |
@@ -362,7 +362,7 @@ static void display_status(int count, int scr_width) | |||
362 | USE_FEATURE_TOP_CPU_USAGE_PERCENTAGE("%3u.%c") | 362 | USE_FEATURE_TOP_CPU_USAGE_PERCENTAGE("%3u.%c") |
363 | "%3u.%c ", | 363 | "%3u.%c ", |
364 | s->pid, get_cached_username(s->uid), s->state, | 364 | s->pid, get_cached_username(s->uid), s->state, |
365 | rss_str_buf, s->ppid, | 365 | vsz_str_buf, s->ppid, |
366 | USE_FEATURE_TOP_CPU_USAGE_PERCENTAGE(pcpu.quot, '0'+pcpu.rem,) | 366 | USE_FEATURE_TOP_CPU_USAGE_PERCENTAGE(pcpu.quot, '0'+pcpu.rem,) |
367 | pmem.quot, '0'+pmem.rem); | 367 | pmem.quot, '0'+pmem.rem); |
368 | if (col > 0) | 368 | if (col > 0) |
@@ -474,7 +474,7 @@ int top_main(int argc, char **argv) | |||
474 | while ((p = procps_scan(p, 0 | 474 | while ((p = procps_scan(p, 0 |
475 | | PSSCAN_PID | 475 | | PSSCAN_PID |
476 | | PSSCAN_PPID | 476 | | PSSCAN_PPID |
477 | | PSSCAN_RSS | 477 | | PSSCAN_VSZ |
478 | | PSSCAN_STIME | 478 | | PSSCAN_STIME |
479 | | PSSCAN_UTIME | 479 | | PSSCAN_UTIME |
480 | | PSSCAN_STATE | 480 | | PSSCAN_STATE |
@@ -486,7 +486,7 @@ int top_main(int argc, char **argv) | |||
486 | top = xrealloc(top, (++ntop)*sizeof(top_status_t)); | 486 | top = xrealloc(top, (++ntop)*sizeof(top_status_t)); |
487 | top[n].pid = p->pid; | 487 | top[n].pid = p->pid; |
488 | top[n].ppid = p->ppid; | 488 | top[n].ppid = p->ppid; |
489 | top[n].rss = p->rss; | 489 | top[n].vsz = p->vsz; |
490 | #if ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE | 490 | #if ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE |
491 | top[n].ticks = p->stime + p->utime; | 491 | top[n].ticks = p->stime + p->utime; |
492 | #endif | 492 | #endif |