aboutsummaryrefslogtreecommitdiff
path: root/procps/top.c
diff options
context:
space:
mode:
authorvapier <vapier@69ca8d6d-28ef-0310-b511-8ec308f3f277>2007-02-08 08:21:58 +0000
committervapier <vapier@69ca8d6d-28ef-0310-b511-8ec308f3f277>2007-02-08 08:21:58 +0000
commit2f011cf6459116975eb15cb85a9d7949c1eba9f4 (patch)
tree72424e60f565c397b8a2b10f88855f11b46c4010 /procps/top.c
parent69e92e11b82f87b212ce9aa14596042339d0288c (diff)
downloadbusybox-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
Diffstat (limited to 'procps/top.c')
-rw-r--r--procps/top.c42
1 files changed, 21 insertions, 21 deletions
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