Updated with Tizen:Base source codes
[external/procps.git] / packaging / procps-3.2.7-vmstat-timestamp.patch
1 --- procps-3.2.7/vmstat.c       2008-12-11 22:11:30.042532106 -0500
2 +++ procps-3.2.7/vmstat.c.timestamp     2008-12-11 22:08:11.553529883 -0500
3 @@ -25,6 +25,7 @@
4  #include <sys/ioctl.h>
5  #include <sys/dir.h>
6  #include <dirent.h>
7 +#include <time.h>
8  
9  #include "proc/sysinfo.h"
10  #include "proc/version.h"
11 @@ -56,6 +57,7 @@
12  
13  static unsigned int height;   // window height
14  static unsigned int moreheaders=TRUE;
15 +static unsigned int showtimestamp=FALSE;
16  
17  
18  /////////////////////////////////////////////////////////////////////////
19 @@ -71,6 +73,7 @@
20    fprintf(stderr,"              -p prints disk partition statistics\n");
21    fprintf(stderr,"              -s prints vm table\n");
22    fprintf(stderr,"              -m prints slabinfo\n");
23 +  fprintf(stderr,"              -t add timestamp to output\n");
24    fprintf(stderr,"              -S unit size\n");
25    fprintf(stderr,"              delay is the delay between updates in seconds. \n");
26    fprintf(stderr,"              unit size k:1000 K:1024 m:1000000 M:1048576 (default is K)\n");
27 @@ -150,7 +153,11 @@
28  ////////////////////////////////////////////////////////////////////////////
29  
30  static void new_header(void){
31 -  printf("procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu-----\n");
32 +  if(!showtimestamp){
33 +     printf("procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu-----\n");
34 +  } else {
35 +     printf("procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu------ ---timestamp---\n");
36 +  }
37    printf(
38      "%2s %2s %6s %6s %6s %6s %4s %4s %5s %5s %4s %4s %2s %2s %2s %2s %2s\n",
39      "r","b",
40 @@ -173,7 +180,7 @@
41  ////////////////////////////////////////////////////////////////////////////
42  
43  static void new_format(void) {
44 -  const char format[]="%2u %2u %6lu %6lu %6lu %6lu %4u %4u %5u %5u %4u %4u %2u %2u %2u %2u %2u\n";
45 +  const char format[]="%2u %2u %6lu %6lu %6lu %6lu %4u %4u %5u %5u %4u %4u %2u %2u %2u %2u %2u\t%s\n";
46    unsigned int tog=0; /* toggle switch for cleaner code */
47    unsigned int i;
48    unsigned int hz = Hertz;
49 @@ -185,6 +192,10 @@
50    unsigned int sleep_half; 
51    unsigned long kb_per_page = sysconf(_SC_PAGESIZE) / 1024ul;
52    int debt = 0;  // handle idle ticks running backwards
53 +  struct tm *tm_ptr;
54 +  time_t the_time;
55 +  char timebuf[32];
56 +  timebuf[0] = '\0';
57  
58    sleep_half=(sleep_time/2);
59    new_header();
60 @@ -196,6 +207,13 @@
61           &running,&blocked,
62           &dummy_1, &dummy_2);
63  
64 +  if (showtimestamp)
65 +  {
66 +     (void) time( &the_time );
67 +     tm_ptr = localtime( &the_time );
68 +     strftime(timebuf, sizeof(timebuf), "%Y-%m-%d %H:%M:%S %Z", tm_ptr);
69 +  }
70 +
71    duse= *cpu_use + *cpu_nic; 
72    dsys= *cpu_sys + *cpu_xxx + *cpu_yyy;
73    didl= *cpu_idl;
74 @@ -218,7 +236,8 @@
75          (unsigned)( (100*dsys                    + divo2) / Div ),
76          (unsigned)( (100*didl                    + divo2) / Div ),
77          (unsigned)( (100*diow                    + divo2) / Div ),
78 -        (unsigned)( (100*dstl                    + divo2) / Div )
79 +        (unsigned)( (100*dstl                    + divo2) / Div ),
80 +        timebuf
81    );
82  
83    for(i=1;i<num_updates;i++) { /* \\\\\\\\\\\\\\\\\\\\ main loop ////////////////// */
84 @@ -234,6 +253,13 @@
85           &running,&blocked,
86           &dummy_1,&dummy_2);
87  
88 +    if (showtimestamp)
89 +    {
90 +       (void) time( &the_time );
91 +       tm_ptr = localtime( &the_time );
92 +       strftime(timebuf, sizeof(timebuf), "%Y-%m-%d %H:%M:%S %Z", tm_ptr);
93 +    }
94 +
95      duse= cpu_use[tog]-cpu_use[!tog] + cpu_nic[tog]-cpu_nic[!tog];
96      dsys= cpu_sys[tog]-cpu_sys[!tog] + cpu_xxx[tog]-cpu_xxx[!tog] + cpu_yyy[tog]-cpu_yyy[!tog];
97      didl= cpu_idl[tog]-cpu_idl[!tog];
98 @@ -267,7 +293,8 @@
99            (unsigned)( (100*dsys+divo2)/Div ), /*sy*/
100            (unsigned)( (100*didl+divo2)/Div ), /*id*/
101            (unsigned)( (100*diow+divo2)/Div ), //wa
102 -          (unsigned)( (100*dstl+divo2)/Div )  //st
103 +          (unsigned)( (100*dstl+divo2)/Div ), //st
104 +          timebuf /* timestamp */
105      );
106    }
107  }
108 @@ -641,6 +668,9 @@
109        case 's':
110          statMode |= VMSUMSTAT;         
111         break;
112 +      case 't':
113 +        showtimestamp=TRUE;
114 +        break;
115        default:
116         /* no other aguments defined yet. */
117         usage();