]> granicus.if.org Git - sysstat/commitdiff
sar now tells sadc to read only the necessary groups of activities.
authorSebastien Godard <sysstat@orange.fr>
Fri, 12 Nov 2010 15:44:21 +0000 (16:44 +0100)
committerSebastien Godard <sysstat@orange.fr>
Fri, 12 Nov 2010 15:44:21 +0000 (16:44 +0100)
We noticed that a simple command like "sar 0" had a small delay before
displaying the CPU statsitics since system startup. This was because
in every case sar called sadc with option -S ALL resulting in all
possible activities being read.
Now, except if sar's option -o is used (in which case all possible
activities will still be read), sar tells sadc to read only the groups
of activities that include those that will be displayed on screen.

CHANGES
sadc.c
sar.c

diff --git a/CHANGES b/CHANGES
index 64e9cbc768520d8fdab6236e1bee7e08affa025b..6871da8434014fe3afd7b8c44d6966219a6e772f 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,8 @@
 Changes:
 
 xxxx/xx/xx: Version 9.1.7 - Sebastien Godard (sysstat <at> orange.fr)
+       * sar now tells sadc to read only the necessary groups of
+         activities.
        * sar manual page updated.
 
 2010/11/10: Version 9.1.6 - Sebastien Godard (sysstat <at> orange.fr)
diff --git a/sadc.c b/sadc.c
index 9a16b5c6a5ab7a4a7f0be09f5b221db80c19819a..54f1c7dcc9c87eb249a5ba3bf6ea0f1e50d3ee65 100644 (file)
--- a/sadc.c
+++ b/sadc.c
@@ -164,14 +164,24 @@ void parse_sadc_S_option(char *argv[], int opt)
                         * Although undocumented, option -S followed by a numerical value
                         * enables the user to select each activity that should be
                         * collected. "-S 0" unselects all activities but CPU.
+                        * A value greater than 255 enables the user to select groups
+                        * of activities.
                         */
                        int act_id;
 
                        act_id = atoi(argv[opt]);
-                       if ((act_id < 0) || (act_id > NR_ACT)) {
+                       if (act_id > 255) {
+                               act_id >>= 8;
+                               for (i = 0; i < NR_ACT; i++) {
+                                       if (act[i]->group & act_id) {
+                                               act[i]->options |= AO_COLLECTED;
+                                       }
+                               }
+                       }
+                       else if ((act_id < 0) || (act_id > NR_ACT)) {
                                usage(argv[0]);
                        }
-                       if (!act_id) {
+                       else if (!act_id) {
                                /* Unselect all activities but CPU */
                                for (i = 0; i < NR_ACT; i++) {
                                        act[i]->options &= ~AO_COLLECTED;
diff --git a/sar.c b/sar.c
index c9fc5b6701bdcb0ca25fb2f6d107dc10ea176d2f..9fcc0f76c6d5298e4b0521e34d596b28e6f3204f 100644 (file)
--- a/sar.c
+++ b/sar.c
@@ -1057,7 +1057,7 @@ void read_stats(void)
  */
 int main(int argc, char **argv)
 {
-       int opt = 1, args_idx = 2;
+       int i, opt = 1, args_idx = 2;
        int fd[2];
        char from_file[MAX_FILE_LEN], to_file[MAX_FILE_LEN];
        char ltemp[20];
@@ -1322,13 +1322,35 @@ int main(int argc, char **argv)
 
                /* Flags to be passed to sadc */
                salloc(args_idx++, "-z");
-               salloc(args_idx++, "-S");
-               salloc(args_idx++, K_ALL);
-
-               /* Outfile arg */
+               
+               /* Writing data to a file (option -o) */
                if (to_file[0]) {
+                       /* Collect all possible activities (option -S ALL for sadc) */
+                       salloc(args_idx++, "-S");
+                       salloc(args_idx++, K_ALL);
+                       /* Outfile arg */
                        salloc(args_idx++, to_file);
                }
+               else {
+                       /*
+                        * If option -o hasn't been used, then tell sadc
+                        * to collect only activities that will be displayed.
+                        */
+                       int act_id = 0;
+                       
+                       for (i = 0; i < NR_ACT; i++) {
+                               if (IS_SELECTED(act[i]->options)) {
+                                       act_id |= act[i]->group;
+                               }
+                       }
+                       if (act_id) {
+                               act_id <<= 8;
+                               snprintf(ltemp, 19, "%d", act_id);
+                               ltemp[19] = '\0';
+                               salloc(args_idx++, "-S");
+                               salloc(args_idx++, ltemp);
+                       }
+               }
 
                /* Last arg is NULL */
                args[args_idx] = NULL;