From: Sebastien GODARD Date: Fri, 7 Jun 2019 13:31:46 +0000 (+0200) Subject: sar/sadf: Allow to select individual CPU/interrupts with option -A X-Git-Tag: v12.1.6~41 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f73fda5b80bbf1d1577b5dac13ddf23fc59ba241;p=sysstat sar/sadf: Allow to select individual CPU/interrupts with option -A Previously, using option -A with sar or sadf would display statistics for all CPU and interrupts (i.e. using -A would also imply -P ALL -I ALL). Now this will be true only if the user didn't specify explicitly a list of CPU or interrupts using options -P or -I. Example: "sar -A -P1,4" will display all possible statistics but only those concerning CPU 1 and 4 for CPU-related metrics. Signed-off-by: Sebastien GODARD --- diff --git a/sa.h b/sa.h index ab98c4b..b8776f9 100644 --- a/sa.h +++ b/sa.h @@ -111,6 +111,9 @@ #define S_F_ZERO_OMIT 0x02000000 #define S_F_SVG_SHOW_TOC 0x04000000 #define S_F_FDATASYNC 0x08000000 +#define S_F_OPTION_A 0x10000000 +#define S_F_OPTION_P 0x20000000 +#define S_F_OPTION_I 0x40000000 #define WANT_SINCE_BOOT(m) (((m) & S_F_SINCE_BOOT) == S_F_SINCE_BOOT) #define WANT_SA_ROTAT(m) (((m) & S_F_SA_ROTAT) == S_F_SA_ROTAT) @@ -132,15 +135,18 @@ #define DISPLAY_ZERO_OMIT(m) (((m) & S_F_ZERO_OMIT) == S_F_ZERO_OMIT) #define DISPLAY_DEBUG_MODE(m) (((m) & S_F_RAW_DEBUG_MODE) == S_F_RAW_DEBUG_MODE) #define AUTOSCALE_ON(m) (((m) & S_F_SVG_AUTOSCALE) == S_F_SVG_AUTOSCALE) -#define DISPLAY_ONE_DAY(m) (((m) & S_F_SVG_ONE_DAY) == S_F_SVG_ONE_DAY) +#define DISPLAY_ONE_DAY(m) (((m) & S_F_SVG_ONE_DAY) == S_F_SVG_ONE_DAY) #define DISPLAY_IDLE(m) (((m) & S_F_SVG_SHOW_IDLE) == S_F_SVG_SHOW_IDLE) #define DISPLAY_INFO(m) (((m) & S_F_SVG_SHOW_INFO) == S_F_SVG_SHOW_INFO) -#define DISPLAY_UNIT(m) (((m) & S_F_UNIT) == S_F_UNIT) -#define SET_CANVAS_HEIGHT(m) (((m) & S_F_SVG_HEIGHT) == S_F_SVG_HEIGHT) -#define PACK_VIEWS(m) (((m) & S_F_SVG_PACKED) == S_F_SVG_PACKED) -#define DISPLAY_HUMAN_READ(m) (((m) & S_F_HUMAN_READ) == S_F_HUMAN_READ) +#define DISPLAY_UNIT(m) (((m) & S_F_UNIT) == S_F_UNIT) +#define SET_CANVAS_HEIGHT(m) (((m) & S_F_SVG_HEIGHT) == S_F_SVG_HEIGHT) +#define PACK_VIEWS(m) (((m) & S_F_SVG_PACKED) == S_F_SVG_PACKED) +#define DISPLAY_HUMAN_READ(m) (((m) & S_F_HUMAN_READ) == S_F_HUMAN_READ) #define DISPLAY_TOC(m) (((m) & S_F_SVG_SHOW_TOC) == S_F_SVG_SHOW_TOC) #define FDATASYNC(m) (((m) & S_F_FDATASYNC) == S_F_FDATASYNC) +#define USE_OPTION_A(m) (((m) & S_F_OPTION_A) == S_F_OPTION_A) +#define USE_OPTION_P(m) (((m) & S_F_OPTION_P) == S_F_OPTION_P) +#define USE_OPTION_I(m) (((m) & S_F_OPTION_I) == S_F_OPTION_I) #define AO_F_NULL 0x00000000 @@ -1384,7 +1390,7 @@ void parse_sa_devices int parse_sar_opt (char * [], int *, struct activity * [], unsigned int *, int); int parse_sar_I_opt - (char * [], int *, struct activity * []); + (char * [], int *, unsigned int *, struct activity * []); int parse_sa_P_opt (char * [], int *, unsigned int *, struct activity * []); int parse_sar_m_opt @@ -1428,8 +1434,8 @@ void select_all_activities (struct activity * []); void select_default_activity (struct activity * []); -void set_bitmap - (unsigned char [], unsigned char, unsigned int); +void set_bitmaps + (struct activity * [], unsigned int *); void set_hdr_rectime (unsigned int, struct tm *, struct file_header *); void set_record_timestamp_string diff --git a/sa_common.c b/sa_common.c index d615d8c..82f2d2b 100644 --- a/sa_common.c +++ b/sa_common.c @@ -2110,21 +2110,19 @@ int parse_sar_opt(char *argv[], int *opt, struct activity *act[], case 'A': select_all_activities(act); + *flags |= S_F_OPTION_A; /* - * Force '-P ALL -I ALL -r ALL -u ALL -F'. + * Force '-r ALL -u ALL -F'. * Setting -F is compulsory because corresponding activity * has AO_MULTIPLE_OUTPUTS flag set. + * -P ALL / -I ALL will be set only corresponding option has + * not been exlicitly entered on the command line. */ p = get_activity_position(act, A_MEMORY, EXIT_IF_NOT_FOUND); act[p]->opt_flags |= AO_F_MEMORY + AO_F_SWAP + AO_F_MEM_ALL; - p = get_activity_position(act, A_IRQ, EXIT_IF_NOT_FOUND); - memset(act[p]->bitmap->b_array, ~0, - BITMAP_SIZE(act[p]->bitmap->b_size)); p = get_activity_position(act, A_CPU, EXIT_IF_NOT_FOUND); - memset(act[p]->bitmap->b_array, ~0, - BITMAP_SIZE(act[p]->bitmap->b_size)); act[p]->opt_flags = AO_F_CPU_ALL; p = get_activity_position(act, A_FS, EXIT_IF_NOT_FOUND); @@ -2451,13 +2449,14 @@ int parse_sar_n_opt(char *argv[], int *opt, struct activity *act[]) * @act Array of activities. * * OUT: + * @flags Common flags and system state. * @act Array of activities, with interrupts activity selected. * * RETURNS: * 0 on success, 1 otherwise. *************************************************************************** */ -int parse_sar_I_opt(char *argv[], int *opt, struct activity *act[]) +int parse_sar_I_opt(char *argv[], int *opt, unsigned int *flags, struct activity *act[]) { int p; @@ -2470,6 +2469,7 @@ int parse_sar_I_opt(char *argv[], int *opt, struct activity *act[]) act[p]->bitmap->b_size, K_SUM)) return 1; (*opt)++; + *flags |= S_F_OPTION_I; return 0; } @@ -2504,12 +2504,44 @@ int parse_sa_P_opt(char *argv[], int *opt, unsigned int *flags, struct activity act[p]->bitmap->b_size, K_LOWERALL)) return 1; (*opt)++; + *flags |= S_F_OPTION_P; return 0; } return 1; } +/* + *************************************************************************** + * If option -A has been used, force -P ALL -I ALL only if corresponding + * option has not been explicitly entered on the command line. + * + * IN: + * @flags Common flags and system state. + * + * OUT: + * @act Array of selected activities. + *************************************************************************** + */ +void set_bitmaps(struct activity *act[], unsigned int *flags) +{ + int p; + + if (!USE_OPTION_P(*flags)) { + /* Force -P ALL */ + p = get_activity_position(act, A_CPU, EXIT_IF_NOT_FOUND); + memset(act[p]->bitmap->b_array, ~0, + BITMAP_SIZE(act[p]->bitmap->b_size)); + } + + if (!USE_OPTION_I(*flags)) { + /* Force -I ALL */ + p = get_activity_position(act, A_IRQ, EXIT_IF_NOT_FOUND); + memset(act[p]->bitmap->b_array, ~0, + BITMAP_SIZE(act[p]->bitmap->b_size)); + } +} + /* *************************************************************************** * Count number of comma-separated values in arguments list. For example, diff --git a/sadf.c b/sadf.c index 2b35c42..78b6b3d 100644 --- a/sadf.c +++ b/sadf.c @@ -1513,7 +1513,7 @@ int main(int argc, char **argv) if (!sar_options) { usage(argv[0]); } - if (parse_sar_I_opt(argv, &opt, act)) { + if (parse_sar_I_opt(argv, &opt, &flags, act)) { usage(argv[0]); } } @@ -1803,6 +1803,11 @@ int main(int argc, char **argv) } } + if (USE_OPTION_A(flags)) { + /* Set -P ALL -I ALL if needed */ + set_bitmaps(act, &flags); + } + /* sadf reads current daily data file by default */ if (!dfile[0]) { set_default_file(dfile, day_offset, -1); diff --git a/sar.c b/sar.c index f0db4ad..94dd5e9 100644 --- a/sar.c +++ b/sar.c @@ -1317,7 +1317,7 @@ int main(int argc, char **argv) else if (!strcmp(argv[opt], "-I")) { /* Parse -I option */ - if (parse_sar_I_opt(argv, &opt, act)) { + if (parse_sar_I_opt(argv, &opt, &flags, act)) { usage(argv[0]); } } @@ -1490,6 +1490,10 @@ int main(int argc, char **argv) fprintf(stderr, _("-f and -o options are mutually exclusive\n")); exit(1); } + if (USE_OPTION_A(flags)) { + /* Set -P ALL -I ALL if needed */ + set_bitmaps(act, &flags); + } /* Use time start or option -i only when reading stats from a file */ if ((tm_start.use || INTERVAL_SET(flags)) && !from_file[0]) { fprintf(stderr,