From eb312a4186ab83d483184cc87dd8ff99d5d5d96a Mon Sep 17 00:00:00 2001 From: Sebastien Godard Date: Mon, 1 Nov 2010 13:18:11 +0100 Subject: [PATCH] Define groups of activities: Each activity has now a new attribute specifying the group it belongs to (POWER, IPV6, etc.) Add a new attribute to the activity structure, defining the group the activity belongs to. This makes to code more generic, as it is no longer necessary to update sadc.c whenever a new activity is added to a group. --- CHANGES | 2 ++ activity.c | 35 ++++++++++++++++++++++++++++ sa.h | 33 ++++++++++++++++++++------ sa_common.c | 7 ++++-- sadc.c | 67 ++++++++++++++++++++++++++++------------------------- 5 files changed, 104 insertions(+), 40 deletions(-) diff --git a/CHANGES b/CHANGES index 594f7b3..3195f86 100644 --- a/CHANGES +++ b/CHANGES @@ -12,6 +12,8 @@ xxxx/xx/xx: Version 9.1.6 - Sebastien Godard (sysstat orange.fr) sadf -x) and DTD document. * sadc -S POWER didn't include voltage inputs statistics. This is now fixed. + * Define groups of activities: Each activity has now a new + attribute specifying the group it belongs to (POWER, IPV6, etc.) * [Ivana Varekova]: Moved manual pages to $prefix/share/man instead of $prefix/man. * [Ivana Varekova]: Fixed configure's --disable-man-group option. diff --git a/activity.c b/activity.c index bb51aa1..8d3ce25 100644 --- a/activity.c +++ b/activity.c @@ -68,6 +68,7 @@ struct activity cpu_act = { .id = A_CPU, .options = AO_COLLECTED + AO_REMANENT + AO_GLOBAL_ITV + AO_MULTIPLE_OUTPUTS, .magic = ACTIVITY_MAGIC_BASE, + .group = G_DEFAULT, #ifdef SOURCE_SADC .f_count = wrap_get_cpu_nr, .f_count2 = NULL, @@ -98,6 +99,7 @@ struct activity pcsw_act = { .id = A_PCSW, .options = AO_COLLECTED, .magic = ACTIVITY_MAGIC_BASE, + .group = G_DEFAULT, #ifdef SOURCE_SADC .f_count = NULL, .f_count2 = NULL, @@ -127,6 +129,7 @@ struct activity irq_act = { .id = A_IRQ, .options = AO_NULL, .magic = ACTIVITY_MAGIC_BASE, + .group = G_INT, #ifdef SOURCE_SADC .f_count = wrap_get_irq_nr, .f_count2 = NULL, @@ -156,6 +159,7 @@ struct activity swap_act = { .id = A_SWAP, .options = AO_COLLECTED, .magic = ACTIVITY_MAGIC_BASE, + .group = G_DEFAULT, #ifdef SOURCE_SADC .f_count = NULL, .f_count2 = NULL, @@ -185,6 +189,7 @@ struct activity paging_act = { .id = A_PAGE, .options = AO_COLLECTED, .magic = ACTIVITY_MAGIC_BASE, + .group = G_DEFAULT, #ifdef SOURCE_SADC .f_count = NULL, .f_count2 = NULL, @@ -215,6 +220,7 @@ struct activity io_act = { .id = A_IO, .options = AO_COLLECTED, .magic = ACTIVITY_MAGIC_BASE, + .group = G_DEFAULT, #ifdef SOURCE_SADC .f_count = NULL, .f_count2 = NULL, @@ -244,6 +250,7 @@ struct activity memory_act = { .id = A_MEMORY, .options = AO_COLLECTED + AO_MULTIPLE_OUTPUTS, .magic = ACTIVITY_MAGIC_BASE, + .group = G_DEFAULT, #ifdef SOURCE_SADC .f_count = NULL, .f_count2 = NULL, @@ -275,6 +282,7 @@ struct activity ktables_act = { .id = A_KTABLES, .options = AO_COLLECTED, .magic = ACTIVITY_MAGIC_BASE, + .group = G_DEFAULT, #ifdef SOURCE_SADC .f_count = NULL, .f_count2 = NULL, @@ -304,6 +312,7 @@ struct activity queue_act = { .id = A_QUEUE, .options = AO_COLLECTED, .magic = ACTIVITY_MAGIC_BASE, + .group = G_DEFAULT, #ifdef SOURCE_SADC .f_count = NULL, .f_count2 = NULL, @@ -333,6 +342,7 @@ struct activity serial_act = { .id = A_SERIAL, .options = AO_COLLECTED, .magic = ACTIVITY_MAGIC_BASE, + .group = G_DEFAULT, #ifdef SOURCE_SADC .f_count = wrap_get_serial_nr, .f_count2 = NULL, @@ -362,6 +372,7 @@ struct activity disk_act = { .id = A_DISK, .options = AO_NULL, .magic = ACTIVITY_MAGIC_BASE, + .group = G_DISK, #ifdef SOURCE_SADC .f_count = wrap_get_disk_nr, .f_count2 = NULL, @@ -391,6 +402,7 @@ struct activity net_dev_act = { .id = A_NET_DEV, .options = AO_COLLECTED, .magic = ACTIVITY_MAGIC_BASE, + .group = G_DEFAULT, #ifdef SOURCE_SADC .f_count = wrap_get_iface_nr, .f_count2 = NULL, @@ -420,6 +432,7 @@ struct activity net_edev_act = { .id = A_NET_EDEV, .options = AO_COLLECTED, .magic = ACTIVITY_MAGIC_BASE, + .group = G_DEFAULT, #ifdef SOURCE_SADC .f_count = wrap_get_iface_nr, .f_count2 = NULL, @@ -450,6 +463,7 @@ struct activity net_nfs_act = { .id = A_NET_NFS, .options = AO_COLLECTED, .magic = ACTIVITY_MAGIC_BASE, + .group = G_DEFAULT, #ifdef SOURCE_SADC .f_count = NULL, .f_count2 = NULL, @@ -479,6 +493,7 @@ struct activity net_nfsd_act = { .id = A_NET_NFSD, .options = AO_COLLECTED, .magic = ACTIVITY_MAGIC_BASE, + .group = G_DEFAULT, #ifdef SOURCE_SADC .f_count = NULL, .f_count2 = NULL, @@ -509,6 +524,7 @@ struct activity net_sock_act = { .id = A_NET_SOCK, .options = AO_COLLECTED, .magic = ACTIVITY_MAGIC_BASE, + .group = G_DEFAULT, #ifdef SOURCE_SADC .f_count = NULL, .f_count2 = NULL, @@ -538,6 +554,7 @@ struct activity net_ip_act = { .id = A_NET_IP, .options = AO_NULL, .magic = ACTIVITY_MAGIC_BASE, + .group = G_SNMP, #ifdef SOURCE_SADC .f_count = NULL, .f_count2 = NULL, @@ -567,6 +584,7 @@ struct activity net_eip_act = { .id = A_NET_EIP, .options = AO_NULL, .magic = ACTIVITY_MAGIC_BASE, + .group = G_SNMP, #ifdef SOURCE_SADC .f_count = NULL, .f_count2 = NULL, @@ -596,6 +614,7 @@ struct activity net_icmp_act = { .id = A_NET_ICMP, .options = AO_NULL, .magic = ACTIVITY_MAGIC_BASE, + .group = G_SNMP, #ifdef SOURCE_SADC .f_count = NULL, .f_count2 = NULL, @@ -626,6 +645,7 @@ struct activity net_eicmp_act = { .id = A_NET_EICMP, .options = AO_NULL, .magic = ACTIVITY_MAGIC_BASE, + .group = G_SNMP, #ifdef SOURCE_SADC .f_count = NULL, .f_count2 = NULL, @@ -656,6 +676,7 @@ struct activity net_tcp_act = { .id = A_NET_TCP, .options = AO_NULL, .magic = ACTIVITY_MAGIC_BASE, + .group = G_SNMP, #ifdef SOURCE_SADC .f_count = NULL, .f_count2 = NULL, @@ -685,6 +706,7 @@ struct activity net_etcp_act = { .id = A_NET_ETCP, .options = AO_NULL, .magic = ACTIVITY_MAGIC_BASE, + .group = G_SNMP, #ifdef SOURCE_SADC .f_count = NULL, .f_count2 = NULL, @@ -714,6 +736,7 @@ struct activity net_udp_act = { .id = A_NET_UDP, .options = AO_NULL, .magic = ACTIVITY_MAGIC_BASE, + .group = G_SNMP, #ifdef SOURCE_SADC .f_count = NULL, .f_count2 = NULL, @@ -743,6 +766,7 @@ struct activity net_sock6_act = { .id = A_NET_SOCK6, .options = AO_NULL, .magic = ACTIVITY_MAGIC_BASE, + .group = G_IPV6, #ifdef SOURCE_SADC .f_count = NULL, .f_count2 = NULL, @@ -772,6 +796,7 @@ struct activity net_ip6_act = { .id = A_NET_IP6, .options = AO_NULL, .magic = ACTIVITY_MAGIC_BASE, + .group = G_IPV6, #ifdef SOURCE_SADC .f_count = NULL, .f_count2 = NULL, @@ -802,6 +827,7 @@ struct activity net_eip6_act = { .id = A_NET_EIP6, .options = AO_NULL, .magic = ACTIVITY_MAGIC_BASE, + .group = G_IPV6, #ifdef SOURCE_SADC .f_count = NULL, .f_count2 = NULL, @@ -832,6 +858,7 @@ struct activity net_icmp6_act = { .id = A_NET_ICMP6, .options = AO_NULL, .magic = ACTIVITY_MAGIC_BASE, + .group = G_IPV6, #ifdef SOURCE_SADC .f_count = NULL, .f_count2 = NULL, @@ -863,6 +890,7 @@ struct activity net_eicmp6_act = { .id = A_NET_EICMP6, .options = AO_NULL, .magic = ACTIVITY_MAGIC_BASE, + .group = G_IPV6, #ifdef SOURCE_SADC .f_count = NULL, .f_count2 = NULL, @@ -893,6 +921,7 @@ struct activity net_udp6_act = { .id = A_NET_UDP6, .options = AO_CLOSE_MARKUP, .magic = ACTIVITY_MAGIC_BASE, + .group = G_IPV6, #ifdef SOURCE_SADC .f_count = NULL, .f_count2 = NULL, @@ -922,6 +951,7 @@ struct activity pwr_cpufreq_act = { .id = A_PWR_CPUFREQ, .options = AO_NULL, .magic = ACTIVITY_MAGIC_BASE, + .group = G_POWER, #ifdef SOURCE_SADC .f_count = wrap_get_cpu_nr, .f_count2 = NULL, @@ -951,6 +981,7 @@ struct activity pwr_fan_act = { .id = A_PWR_FAN, .options = AO_NULL, .magic = ACTIVITY_MAGIC_BASE, + .group = G_POWER, #ifdef SOURCE_SADC .f_count = wrap_get_fan_nr, .f_count2 = NULL, @@ -980,6 +1011,7 @@ struct activity pwr_temp_act = { .id = A_PWR_TEMP, .options = AO_NULL, .magic = ACTIVITY_MAGIC_BASE, + .group = G_POWER, #ifdef SOURCE_SADC .f_count = wrap_get_temp_nr, .f_count2 = NULL, @@ -1009,6 +1041,7 @@ struct activity pwr_in_act = { .id = A_PWR_IN, .options = AO_NULL, .magic = ACTIVITY_MAGIC_BASE, + .group = G_POWER, #ifdef SOURCE_SADC .f_count = wrap_get_in_nr, .f_count2 = NULL, @@ -1038,6 +1071,7 @@ struct activity huge_act = { .id = A_HUGE, .options = AO_COLLECTED, .magic = ACTIVITY_MAGIC_BASE, + .group = G_DEFAULT, #ifdef SOURCE_SADC .f_count = NULL, .f_count2 = NULL, @@ -1067,6 +1101,7 @@ struct activity pwr_wghfreq_act = { .id = A_PWR_WGHFREQ, .options = AO_CLOSE_MARKUP, .magic = ACTIVITY_MAGIC_BASE, + .group = G_POWER, #ifdef SOURCE_SADC .f_count = wrap_get_cpu_nr, .f_count2 = wrap_get_freq_nr, diff --git a/sa.h b/sa.h index cde99ae..7ce87c0 100644 --- a/sa.h +++ b/sa.h @@ -96,6 +96,8 @@ #define DISPLAY_HORIZONTALLY(m) (((m) & S_F_HORIZONTALLY) == S_F_HORIZONTALLY) #define DISPLAY_COMMENT(m) (((m) & S_F_COMMENT) == S_F_COMMENT) +#define AO_F_NULL 0x00000000 + /* Output flags for options -R / -r / -S */ #define AO_F_MEM_DIA 0x00000001 #define AO_F_MEM_AMT 0x00000002 @@ -138,24 +140,33 @@ #define K_TCP "TCP" #define K_ETCP "ETCP" #define K_UDP "UDP" -#define K_DISK "DISK" -#define K_INT "INT" -#define K_SNMP "SNMP" #define K_SOCK6 "SOCK6" #define K_IP6 "IP6" #define K_EIP6 "EIP6" #define K_ICMP6 "ICMP6" #define K_EICMP6 "EICMP6" #define K_UDP6 "UDP6" -#define K_IPV6 "IPV6" -#define K_POWER "POWER" -#define K_XDISK "XDISK" #define K_CPU "CPU" #define K_FAN "FAN" #define K_TEMP "TEMP" #define K_IN "IN" #define K_FREQ "FREQ" +#define K_INT "INT" +#define K_DISK "DISK" +#define K_XDISK "XDISK" +#define K_SNMP "SNMP" +#define K_IPV6 "IPV6" +#define K_POWER "POWER" + +/* Groups of activities */ +#define G_DEFAULT 0x00 +#define G_INT 0x01 +#define G_DISK 0x02 +#define G_SNMP 0x04 +#define G_IPV6 0x08 +#define G_POWER 0x10 + /* sadc program */ #define SADC "sadc" @@ -277,7 +288,10 @@ struct act_bitmap { int b_size; }; -/* Structure used to define an activity */ +/* + * Structure used to define an activity. + * Note; This structure can be modified without changing the format of data files. + */ struct activity { /* * This variable contains the identification value (A_...) for this activity. @@ -293,6 +307,11 @@ struct activity { * previous versions. */ unsigned int magic; + /* + * an activity belongs to a group (and only one). + * Groups are those selected with option -S of sadc. + */ + unsigned int group; /* * The f_count() function is used to count the number of * items (serial lines, network interfaces, etc.) -> @nr diff --git a/sa_common.c b/sa_common.c index 09ef785..5a74ee2 100644 --- a/sa_common.c +++ b/sa_common.c @@ -796,6 +796,9 @@ int get_activity_nr(struct activity *act[], unsigned int option, int count_outpu * * IN: * @act Array of activities. + * + * OUT: + * @act Array of activities, all of the being selected. *************************************************************************** */ void select_all_activities(struct activity *act[]) @@ -813,10 +816,10 @@ void select_all_activities(struct activity *act[]) * Also select CPU "all" if no other CPU has been selected. * * IN: - * @act Array of activities. + * @act Array of activities. * * OUT: - * @act Array of activities with CPU activity selected if needed. + * @act Array of activities with CPU activity selected if needed. *************************************************************************** */ void select_default_activity(struct activity *act[]) diff --git a/sadc.c b/sadc.c index fb2df6f..9a16b5c 100644 --- a/sadc.c +++ b/sadc.c @@ -87,6 +87,29 @@ void usage(char *progname) exit(1); } +/* + *************************************************************************** + * Collect all activities belonging to a group. + * + * IN: + * @group_id Group identification number. + * @opt_f Optionnal flag to set. + *************************************************************************** + */ +void collect_group_activities(unsigned int group_id, unsigned int opt_f) +{ + int i; + + for (i = 0; i < NR_ACT; i++) { + if (act[i]->group & group_id) { + act[i]->options |= AO_COLLECTED; + if (opt_f) { + act[i]->opt_flags |= opt_f; + } + } + } +} + /* *************************************************************************** * Parse option -S, indicating which activities are to be collected. @@ -103,45 +126,28 @@ void parse_sadc_S_option(char *argv[], int opt) for (p = strtok(argv[opt], ","); p; p = strtok(NULL, ",")) { if (!strcmp(p, K_INT)) { - /* Select interrupt activity */ - COLLECT_ACTIVITY(A_IRQ); + /* Select group of interrupt activities */ + collect_group_activities(G_INT, AO_F_NULL); } else if (!strcmp(p, K_DISK)) { - /* Select disk activity */ - COLLECT_ACTIVITY(A_DISK); + /* Select group of disk activities */ + collect_group_activities(G_DISK, AO_F_NULL); } else if (!strcmp(p, K_XDISK)) { - /* Select disk and partition activity */ - i = get_activity_position(act, A_DISK); - act[i]->options |= AO_COLLECTED; - act[i]->opt_flags |= AO_F_DISK_PART; + /* Select group of disk and partition activities */ + collect_group_activities(G_DISK, AO_F_DISK_PART); } else if (!strcmp(p, K_SNMP)) { - /* Select SNMP activities */ - COLLECT_ACTIVITY(A_NET_IP); - COLLECT_ACTIVITY(A_NET_EIP); - COLLECT_ACTIVITY(A_NET_ICMP); - COLLECT_ACTIVITY(A_NET_EICMP); - COLLECT_ACTIVITY(A_NET_TCP); - COLLECT_ACTIVITY(A_NET_ETCP); - COLLECT_ACTIVITY(A_NET_UDP); + /* Select group of SNMP activities */ + collect_group_activities(G_SNMP, AO_F_NULL); } else if (!strcmp(p, K_IPV6)) { - /* Select IPv6 activities */ - COLLECT_ACTIVITY(A_NET_IP6); - COLLECT_ACTIVITY(A_NET_EIP6); - COLLECT_ACTIVITY(A_NET_ICMP6); - COLLECT_ACTIVITY(A_NET_EICMP6); - COLLECT_ACTIVITY(A_NET_UDP6); - COLLECT_ACTIVITY(A_NET_SOCK6); + /* Select group of IPv6 activities */ + collect_group_activities(G_IPV6, AO_F_NULL); } else if (!strcmp(p, K_POWER)) { - /* Select activities related to power management */ - COLLECT_ACTIVITY(A_PWR_CPUFREQ); - COLLECT_ACTIVITY(A_PWR_FAN); - COLLECT_ACTIVITY(A_PWR_IN); - COLLECT_ACTIVITY(A_PWR_TEMP); - COLLECT_ACTIVITY(A_PWR_WGHFREQ); + /* Select group of activities related to power management */ + collect_group_activities(G_POWER, AO_F_NULL); } else if (!strcmp(p, K_ALL) || !strcmp(p, K_XALL)) { /* Select all activities */ @@ -150,8 +156,7 @@ void parse_sadc_S_option(char *argv[], int opt) } if (!strcmp(p, K_XALL)) { /* Tell sadc to also collect partition statistics */ - i = get_activity_position(act, A_DISK); - act[i]->opt_flags |= AO_F_DISK_PART; + collect_group_activities(G_DISK, AO_F_DISK_PART); } } else if (strspn(argv[opt], DIGITS) == strlen(argv[opt])) { -- 2.49.0