aboutsummaryrefslogtreecommitdiff
path: root/procps
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2007-02-08 08:21:58 +0000
committerMike Frysinger <vapier@gentoo.org>2007-02-08 08:21:58 +0000
commit0aa6ba5d44af32d0bf460c8d92cda686bae64c92 (patch)
tree72424e60f565c397b8a2b10f88855f11b46c4010 /procps
parent4423e5beefd6f17dfa836211899ee70edcc64a5b (diff)
downloadbusybox-w32-0aa6ba5d44af32d0bf460c8d92cda686bae64c92.tar.gz
busybox-w32-0aa6ba5d44af32d0bf460c8d92cda686bae64c92.tar.bz2
busybox-w32-0aa6ba5d44af32d0bf460c8d92cda686bae64c92.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
Diffstat (limited to 'procps')
-rw-r--r--procps/ps.c16
-rw-r--r--procps/top.c42
2 files changed, 29 insertions, 29 deletions
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
50static void func_rss(char *buf, int size, const procps_status_t *ps) 50static 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
34typedef struct { 34typedef 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;
55static int prev_hist_count; 55static int prev_hist_count;
56/* static int hist_iterations; */ 56/* static int hist_iterations; */
57static unsigned total_pcpu; 57static 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)
72static int mem_sort(top_status_t *P, top_status_t *Q) 72static 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