4cb0c0d28712e178bd94b55da52e2817015c1baf
[busybox-power] / debian / patches / top-display-rss.patch
1 Change top to display RSS instead of VSZ.
2 By Alexander Shishkin <ext-alexander.shishkin@nokia.com>
3
4 Ported to BusyBox 1.19 by Dennis Groenen <tj.groenen@gmail.com> - 2011-08-19
5 ---
6
7 --- a/procps/top.c
8 +++ b/procps/top.c
9 @@ -54,7 +54,7 @@
10  
11  
12  typedef struct top_status_t {
13 -       unsigned long vsz;
14 +       unsigned long rss;
15  #if ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE
16         unsigned long ticks;
17         unsigned pcpu; /* delta of ticks */
18 @@ -166,8 +166,8 @@ static int pid_sort(top_status_t *P, top
19  static int mem_sort(top_status_t *P, top_status_t *Q)
20  {
21         /* We want to avoid unsigned->signed and truncation errors */
22 -       if (Q->vsz < P->vsz) return -1;
23 -       return Q->vsz != P->vsz; /* 0 if ==, 1 if > */
24 +       if (Q->rss < P->rss) return -1;
25 +       return Q->rss != P->rss; /* 0 if ==, 1 if > */
26  }
27  
28  
29 @@ -538,7 +538,7 @@ static NOINLINE void display_process_lis
30  
31         /* what info of the processes is shown */
32         printf(OPT_BATCH_MODE ? "%.*s" : "\033[7m%.*s\033[0m", scr_width,
33 -               "  PID  PPID USER     STAT   VSZ %VSZ"
34 +               "  PID  PPID USER     STAT   RSS %MEM"
35                 IF_FEATURE_TOP_SMP_PROCESS(" CPU")
36                 IF_FEATURE_TOP_CPU_USAGE_PERCENTAGE(" %CPU")
37                 " COMMAND");
38 @@ -556,7 +556,7 @@ static NOINLINE void display_process_lis
39  # define FMT "%4u%%"
40  #endif
41         /*
42 -        * %VSZ = s->vsz/MemTotal
43 +        * %MEM = s->vsz/MemTotal
44          */
45         pmem_shift = BITS_PER_INT-11;
46         pmem_scale = UPSCALE*(1U<<(BITS_PER_INT-11)) / total_memory;
47 @@ -607,16 +607,16 @@ static NOINLINE void display_process_lis
48         s = top;
49         while (--lines_rem >= 0) {
50                 unsigned col;
51 -               CALC_STAT(pmem, (s->vsz*pmem_scale + pmem_half) >> pmem_shift);
52 +               CALC_STAT(pmem, (s->rss*pmem_scale + pmem_half) >> pmem_shift);
53  #if ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE
54                 CALC_STAT(pcpu, (s->pcpu*pcpu_scale + pcpu_half) >> pcpu_shift);
55  #endif
56  
57 -               if (s->vsz >= 100000)
58 -                       sprintf(vsz_str_buf, "%6ldm", s->vsz/1024);
59 +               if (s->rss >= 100000)
60 +                       sprintf(vsz_str_buf, "%6ldm", s->rss/1024);
61                 else
62 -                       sprintf(vsz_str_buf, "%7ld", s->vsz);
63 -               /* PID PPID USER STAT VSZ %VSZ [%CPU] COMMAND */
64 +                       sprintf(vsz_str_buf, "%7ld", s->rss);
65 +               /* PID PPID USER STAT RSS %MEM %CPU COMMAND */
66                 col = snprintf(line_buf, scr_width,
67                                 "\n" "%5u%6u %-8.8s %s%s" FMT
68                                 IF_FEATURE_TOP_SMP_PROCESS(" %3d")
69 @@ -1109,7 +1109,7 @@ int top_main(int argc UNUSED_PARAM, char
70                                 top = xrealloc_vector(top, 6, ntop++);
71                                 top[n].pid = p->pid;
72                                 top[n].ppid = p->ppid;
73 -                               top[n].vsz = p->vsz;
74 +                               top[n].rss = p->rss;
75  #if ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE
76                                 top[n].ticks = p->stime + p->utime;
77  #endif