From: Sebastien GODARD Date: Sat, 13 Nov 2021 14:47:43 +0000 (+0100) Subject: sadc: Reuse count results for sub-items X-Git-Tag: v12.5.5~9 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8641e9d4289d45ce01694eb97da73ca1b39e0bf9;p=sysstat sadc: Reuse count results for sub-items Signed-off-by: Sebastien GODARD --- diff --git a/activity.c b/activity.c index 3f3a3bf..85b34b8 100644 --- a/activity.c +++ b/activity.c @@ -74,7 +74,7 @@ struct activity cpu_act = { .group = G_DEFAULT, #ifdef SOURCE_SADC .f_count_index = 0, /* wrap_get_cpu_nr() */ - .f_count2 = NULL, + .f_count2_index = -1, .f_read = wrap_read_stat_cpu, #endif #ifdef SOURCE_SAR @@ -121,7 +121,7 @@ struct activity pcsw_act = { .group = G_DEFAULT, #ifdef SOURCE_SADC .f_count_index = -1, - .f_count2 = NULL, + .f_count2_index = -1, .f_read = wrap_read_stat_pcsw, #endif #ifdef SOURCE_SAR @@ -167,7 +167,7 @@ struct activity irq_act = { .group = G_INT, #ifdef SOURCE_SADC .f_count_index = 1, /* wrap_get_irq_nr() */ - .f_count2 = NULL, + .f_count2_index = -1, .f_read = wrap_read_stat_irq, #endif #ifdef SOURCE_SAR @@ -213,7 +213,7 @@ struct activity swap_act = { .group = G_DEFAULT, #ifdef SOURCE_SADC .f_count_index = -1, - .f_count2 = NULL, + .f_count2_index = -1, .f_read = wrap_read_swap, #endif #ifdef SOURCE_SAR @@ -259,7 +259,7 @@ struct activity paging_act = { .group = G_DEFAULT, #ifdef SOURCE_SADC .f_count_index = -1, - .f_count2 = NULL, + .f_count2_index = -1, .f_read = wrap_read_paging, #endif #ifdef SOURCE_SAR @@ -306,7 +306,7 @@ struct activity io_act = { .group = G_DEFAULT, #ifdef SOURCE_SADC .f_count_index = -1, - .f_count2 = NULL, + .f_count2_index = -1, .f_read = wrap_read_io, #endif #ifdef SOURCE_SAR @@ -352,7 +352,7 @@ struct activity memory_act = { .group = G_DEFAULT, #ifdef SOURCE_SADC .f_count_index = -1, - .f_count2 = NULL, + .f_count2_index = -1, .f_read = wrap_read_meminfo, #endif #ifdef SOURCE_SAR @@ -399,7 +399,7 @@ struct activity ktables_act = { .group = G_DEFAULT, #ifdef SOURCE_SADC .f_count_index = -1, - .f_count2 = NULL, + .f_count2_index = -1, .f_read = wrap_read_kernel_tables, #endif #ifdef SOURCE_SAR @@ -445,7 +445,7 @@ struct activity queue_act = { .group = G_DEFAULT, #ifdef SOURCE_SADC .f_count_index = -1, - .f_count2 = NULL, + .f_count2_index = -1, .f_read = wrap_read_loadavg, #endif #ifdef SOURCE_SAR @@ -491,7 +491,7 @@ struct activity serial_act = { .group = G_DEFAULT, #ifdef SOURCE_SADC .f_count_index = 2, /* wrap_get_serial_nr() */ - .f_count2 = NULL, + .f_count2_index = -1, .f_read = wrap_read_tty_driver_serial, #endif #ifdef SOURCE_SAR @@ -537,7 +537,7 @@ struct activity disk_act = { .group = G_DISK, #ifdef SOURCE_SADC .f_count_index = 3, /* wrap_get_disk_nr() */ - .f_count2 = NULL, + .f_count2_index = -1, .f_read = wrap_read_disk, #endif #ifdef SOURCE_SAR @@ -583,7 +583,7 @@ struct activity net_dev_act = { .group = G_DEFAULT, #ifdef SOURCE_SADC .f_count_index = 4, /* wrap_get_iface_nr() */ - .f_count2 = NULL, + .f_count2_index = -1, .f_read = wrap_read_net_dev, #endif #ifdef SOURCE_SAR @@ -629,7 +629,7 @@ struct activity net_edev_act = { .group = G_DEFAULT, #ifdef SOURCE_SADC .f_count_index = 4, /* wrap_get_iface_nr() */ - .f_count2 = NULL, + .f_count2_index = -1, .f_read = wrap_read_net_edev, #endif #ifdef SOURCE_SAR @@ -676,7 +676,7 @@ struct activity net_nfs_act = { .group = G_DEFAULT, #ifdef SOURCE_SADC .f_count_index = -1, - .f_count2 = NULL, + .f_count2_index = -1, .f_read = wrap_read_net_nfs, #endif #ifdef SOURCE_SAR @@ -722,7 +722,7 @@ struct activity net_nfsd_act = { .group = G_DEFAULT, #ifdef SOURCE_SADC .f_count_index = -1, - .f_count2 = NULL, + .f_count2_index = -1, .f_read = wrap_read_net_nfsd, #endif #ifdef SOURCE_SAR @@ -769,7 +769,7 @@ struct activity net_sock_act = { .group = G_DEFAULT, #ifdef SOURCE_SADC .f_count_index = -1, - .f_count2 = NULL, + .f_count2_index = -1, .f_read = wrap_read_net_sock, #endif #ifdef SOURCE_SAR @@ -815,7 +815,7 @@ struct activity net_ip_act = { .group = G_SNMP, #ifdef SOURCE_SADC .f_count_index = -1, - .f_count2 = NULL, + .f_count2_index = -1, .f_read = wrap_read_net_ip, #endif #ifdef SOURCE_SAR @@ -861,7 +861,7 @@ struct activity net_eip_act = { .group = G_SNMP, #ifdef SOURCE_SADC .f_count_index = -1, - .f_count2 = NULL, + .f_count2_index = -1, .f_read = wrap_read_net_eip, #endif #ifdef SOURCE_SAR @@ -907,7 +907,7 @@ struct activity net_icmp_act = { .group = G_SNMP, #ifdef SOURCE_SADC .f_count_index = -1, - .f_count2 = NULL, + .f_count2_index = -1, .f_read = wrap_read_net_icmp, #endif #ifdef SOURCE_SAR @@ -954,7 +954,7 @@ struct activity net_eicmp_act = { .group = G_SNMP, #ifdef SOURCE_SADC .f_count_index = -1, - .f_count2 = NULL, + .f_count2_index = -1, .f_read = wrap_read_net_eicmp, #endif #ifdef SOURCE_SAR @@ -1001,7 +1001,7 @@ struct activity net_tcp_act = { .group = G_SNMP, #ifdef SOURCE_SADC .f_count_index = -1, - .f_count2 = NULL, + .f_count2_index = -1, .f_read = wrap_read_net_tcp, #endif #ifdef SOURCE_SAR @@ -1047,7 +1047,7 @@ struct activity net_etcp_act = { .group = G_SNMP, #ifdef SOURCE_SADC .f_count_index = -1, - .f_count2 = NULL, + .f_count2_index = -1, .f_read = wrap_read_net_etcp, #endif #ifdef SOURCE_SAR @@ -1093,7 +1093,7 @@ struct activity net_udp_act = { .group = G_SNMP, #ifdef SOURCE_SADC .f_count_index = -1, - .f_count2 = NULL, + .f_count2_index = -1, .f_read = wrap_read_net_udp, #endif #ifdef SOURCE_SAR @@ -1139,7 +1139,7 @@ struct activity net_sock6_act = { .group = G_IPV6, #ifdef SOURCE_SADC .f_count_index = -1, - .f_count2 = NULL, + .f_count2_index = -1, .f_read = wrap_read_net_sock6, #endif #ifdef SOURCE_SAR @@ -1185,7 +1185,7 @@ struct activity net_ip6_act = { .group = G_IPV6, #ifdef SOURCE_SADC .f_count_index = -1, - .f_count2 = NULL, + .f_count2_index = -1, .f_read = wrap_read_net_ip6, #endif #ifdef SOURCE_SAR @@ -1232,7 +1232,7 @@ struct activity net_eip6_act = { .group = G_IPV6, #ifdef SOURCE_SADC .f_count_index = -1, - .f_count2 = NULL, + .f_count2_index = -1, .f_read = wrap_read_net_eip6, #endif #ifdef SOURCE_SAR @@ -1279,7 +1279,7 @@ struct activity net_icmp6_act = { .group = G_IPV6, #ifdef SOURCE_SADC .f_count_index = -1, - .f_count2 = NULL, + .f_count2_index = -1, .f_read = wrap_read_net_icmp6, #endif #ifdef SOURCE_SAR @@ -1327,7 +1327,7 @@ struct activity net_eicmp6_act = { .group = G_IPV6, #ifdef SOURCE_SADC .f_count_index = -1, - .f_count2 = NULL, + .f_count2_index = -1, .f_read = wrap_read_net_eicmp6, #endif #ifdef SOURCE_SAR @@ -1374,7 +1374,7 @@ struct activity net_udp6_act = { .group = G_IPV6, #ifdef SOURCE_SADC .f_count_index = -1, - .f_count2 = NULL, + .f_count2_index = -1, .f_read = wrap_read_net_udp6, #endif #ifdef SOURCE_SAR @@ -1420,7 +1420,7 @@ struct activity pwr_cpufreq_act = { .group = G_POWER, #ifdef SOURCE_SADC .f_count_index = 0, /* wrap_get_cpu_nr() */ - .f_count2 = NULL, + .f_count2_index = -1, .f_read = wrap_read_cpuinfo, #endif #ifdef SOURCE_SAR @@ -1466,7 +1466,7 @@ struct activity pwr_fan_act = { .group = G_POWER, #ifdef SOURCE_SADC .f_count_index = 5, /* wrap_get_fan_nr() */ - .f_count2 = NULL, + .f_count2_index = -1, .f_read = wrap_read_fan, #endif #ifdef SOURCE_SAR @@ -1512,7 +1512,7 @@ struct activity pwr_temp_act = { .group = G_POWER, #ifdef SOURCE_SADC .f_count_index = 6, /* wrap_get_temp_nr() */ - .f_count2 = NULL, + .f_count2_index = -1, .f_read = wrap_read_temp, #endif #ifdef SOURCE_SAR @@ -1558,7 +1558,7 @@ struct activity pwr_in_act = { .group = G_POWER, #ifdef SOURCE_SADC .f_count_index = 7, /* wrap_get_in_nr() */ - .f_count2 = NULL, + .f_count2_index = -1, .f_read = wrap_read_in, #endif #ifdef SOURCE_SAR @@ -1604,7 +1604,7 @@ struct activity huge_act = { .group = G_DEFAULT, #ifdef SOURCE_SADC .f_count_index = -1, - .f_count2 = NULL, + .f_count2_index = -1, .f_read = wrap_read_meminfo_huge, #endif #ifdef SOURCE_SAR @@ -1650,7 +1650,7 @@ struct activity pwr_wghfreq_act = { .group = G_POWER, #ifdef SOURCE_SADC .f_count_index = 0, /* wrap_get_cpu_nr() */ - .f_count2 = wrap_get_freq_nr, + .f_count2_index = 12, /* wrap_get_freq_nr() */ .f_read = wrap_read_cpu_wghfreq, #endif #ifdef SOURCE_SAR @@ -1695,7 +1695,7 @@ struct activity pwr_usb_act = { .group = G_POWER, #ifdef SOURCE_SADC .f_count_index = 8, /* wrap_get_usb_nr() */ - .f_count2 = NULL, + .f_count2_index = -1, .f_read = wrap_read_bus_usb_dev, #endif #ifdef SOURCE_SAR @@ -1741,7 +1741,7 @@ struct activity filesystem_act = { .group = G_XDISK, #ifdef SOURCE_SADC .f_count_index = 9, /* wrap_get_filesystem_nr() */ - .f_count2 = NULL, + .f_count2_index = -1, .f_read = wrap_read_filesystem, #endif #ifdef SOURCE_SAR @@ -1788,7 +1788,7 @@ struct activity fchost_act = { .group = G_DISK, #ifdef SOURCE_SADC .f_count_index = 10, /* wrap_get_fchost_nr() */ - .f_count2 = NULL, + .f_count2_index = -1, .f_read = wrap_read_fchost, #endif #ifdef SOURCE_SAR @@ -1835,7 +1835,7 @@ struct activity softnet_act = { .group = G_DEFAULT, #ifdef SOURCE_SADC .f_count_index = 0, /* wrap_get_cpu_nr() */ - .f_count2 = NULL, + .f_count2_index = -1, .f_read = wrap_read_softnet, #endif #ifdef SOURCE_SAR @@ -1880,8 +1880,8 @@ struct activity psi_cpu_act = { .magic = ACTIVITY_MAGIC_BASE, .group = G_DEFAULT, #ifdef SOURCE_SADC - .f_count_index = 11, - .f_count2 = NULL, + .f_count_index = 11, /* wrap_detect_psi() */ + .f_count2_index = -1, .f_read = wrap_read_psicpu, #endif #ifdef SOURCE_SAR @@ -1926,8 +1926,8 @@ struct activity psi_io_act = { .magic = ACTIVITY_MAGIC_BASE, .group = G_DEFAULT, #ifdef SOURCE_SADC - .f_count_index = 11, - .f_count2 = NULL, + .f_count_index = 11, /* wrap_detect_psi() */ + .f_count2_index = -1, .f_read = wrap_read_psiio, #endif #ifdef SOURCE_SAR @@ -1972,8 +1972,8 @@ struct activity psi_mem_act = { .magic = ACTIVITY_MAGIC_BASE, .group = G_DEFAULT, #ifdef SOURCE_SADC - .f_count_index = 11, - .f_count2 = NULL, + .f_count_index = 11, /* wrap_detect_psi() */ + .f_count2_index = -1, .f_read = wrap_read_psimem, #endif #ifdef SOURCE_SAR @@ -2010,24 +2010,25 @@ struct activity psi_mem_act = { .buf = {NULL, NULL, NULL}, .bitmap = NULL }; - +/* wrap_detect_psi */ #ifdef SOURCE_SADC /* * Array of functions used to count number of items. */ __nr_t (*f_count[NR_F_COUNT]) (struct activity *) = { - wrap_get_cpu_nr, - wrap_get_irq_nr, - wrap_get_serial_nr, - wrap_get_disk_nr, - wrap_get_iface_nr, - wrap_get_fan_nr, - wrap_get_temp_nr, - wrap_get_in_nr, - wrap_get_usb_nr, - wrap_get_filesystem_nr, - wrap_get_fchost_nr, - wrap_detect_psi + wrap_get_cpu_nr, /* 0 */ + wrap_get_irq_nr, /* 1 */ + wrap_get_serial_nr, /* 2 */ + wrap_get_disk_nr, /* 3 */ + wrap_get_iface_nr, /* 4 */ + wrap_get_fan_nr, /* 5 */ + wrap_get_temp_nr, /* 6 */ + wrap_get_in_nr, /* 7 */ + wrap_get_usb_nr, /* 8 */ + wrap_get_filesystem_nr, /* 9 */ + wrap_get_fchost_nr, /* 10 */ + wrap_detect_psi, /* 11 */ + wrap_get_freq_nr /* 12 */ }; #endif diff --git a/sa.h b/sa.h index 2ec12cc..bc47b6c 100644 --- a/sa.h +++ b/sa.h @@ -25,7 +25,7 @@ #define MAX_NR_ACT 256 /* Number of functions used to count items */ -#define NR_F_COUNT 12 +#define NR_F_COUNT 13 /* Activities */ #define A_CPU 1 @@ -931,15 +931,15 @@ struct activity { */ int f_count_index; /* - * The f_count2() function is used to count the number of - * sub-items -> @nr2 + * Index in f_count[] array to determine function used to count the + * number of sub-items -> @nr2 * Such a function should _always_ return a value greater than * or equal to 0. * - * A NULL value for this function pointer indicates that the number of items - * is a constant (and @nr2 is set to this value). + * A value of -1 indicates that the number of items is a constant + * (and @nr2 is set to this value). */ - __nr_t (*f_count2) (struct activity *); + int f_count2_index; /* * This function reads the relevant file and fill the buffer * with statistics corresponding to given activity. diff --git a/sadc.c b/sadc.c index c4de3a7..0a9ffae 100644 --- a/sadc.c +++ b/sadc.c @@ -341,8 +341,16 @@ void sa_sys_init(void) } if (act[i]->nr_ini > 0) { - if (act[i]->f_count2) { - act[i]->nr2 = (*act[i]->f_count2)(act[i]); + if (act[i]->f_count2_index >= 0) { + idx = act[i]->f_count2_index; + + if (f_count_results[idx] >= 0) { + act[i]->nr2 = f_count_results[idx]; + } + else { + act[i]->nr2 = (f_count[idx])(act[i]); + f_count_results[idx] = act[i]->nr2; + } } /* else act[i]->nr2 is a constant and doesn't need to be calculated */