import local busybox-power tree (1.18.5power2)
[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.18.4 by Dennis Groenen <dennis_groenen@hotmail.com> - 2011-04-29  
5 ---
6
7 --- a/procps/top.c
8 +++ b/procps/top.c
9 @@ -35,7 +35,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 @@ -147,8 +147,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 @@ -519,7 +519,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 %MEM"
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 @@ -588,16 +588,16 @@ static NOINLINE void display_process_lis
39         s = top;
40         while (--lines_rem >= 0) {
41                 unsigned col;
42 -               CALC_STAT(pmem, (s->vsz*pmem_scale + pmem_half) >> pmem_shift);
43 +               CALC_STAT(pmem, (s->rss*pmem_scale + pmem_half) >> pmem_shift);
44  #if ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE
45                 CALC_STAT(pcpu, (s->pcpu*pcpu_scale + pcpu_half) >> pcpu_shift);
46  #endif
47  
48 -               if (s->vsz >= 100000)
49 -                       sprintf(vsz_str_buf, "%6ldm", s->vsz/1024);
50 +               if (s->rss >= 100000)
51 +                       sprintf(vsz_str_buf, "%6ldm", s->rss/1024);
52                 else
53 -                       sprintf(vsz_str_buf, "%7ld", s->vsz);
54 -               /* PID PPID USER STAT VSZ %MEM [%CPU] COMMAND */
55 +                       sprintf(vsz_str_buf, "%7ld", s->rss);
56 +               /* PID PPID USER STAT RSS %MEM %CPU COMMAND */
57                 col = snprintf(line_buf, scr_width,
58                                 "\n" "%5u%6u %-8.8s %s%s" FMT
59                                 IF_FEATURE_TOP_SMP_PROCESS(" %3d")
60 @@ -930,7 +930,7 @@ int top_main(int argc UNUSED_PARAM, char
61                                 top = xrealloc_vector(top, 6, ntop++);
62                                 top[n].pid = p->pid;
63                                 top[n].ppid = p->ppid;
64 -                               top[n].vsz = p->vsz;
65 +                               top[n].rss = p->rss;
66  #if ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE
67                                 top[n].ticks = p->stime + p->utime;
68  #endif