From: Sebastien Godard Date: Fri, 12 Nov 2010 15:44:21 +0000 (+0100) Subject: sar now tells sadc to read only the necessary groups of activities. X-Git-Tag: v9.1.7~11 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1dd72028c319181445030c94e69f77e14d7e5a00;p=sysstat sar now tells sadc to read only the necessary groups of activities. 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. --- diff --git a/CHANGES b/CHANGES index 64e9cbc..6871da8 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,8 @@ Changes: xxxx/xx/xx: Version 9.1.7 - Sebastien Godard (sysstat 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 orange.fr) diff --git a/sadc.c b/sadc.c index 9a16b5c..54f1c7d 100644 --- 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 c9fc5b6..9fcc0f7 100644 --- 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;