From: Sebastien GODARD Date: Fri, 20 Jul 2018 06:20:20 +0000 (+0200) Subject: sar/sadf: Devices list management code refactoring X-Git-Tag: v12.0.0~14 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=55b6c6dee9e5ce17a49d3eb1c1e02adf9b248830;p=sysstat sar/sadf: Devices list management code refactoring No longer use separate lists for devices entered on the command line with options --dev, --iface and --fs. Devices are now saved in the list @item_list which is part of structure activity. This is a linked list whose number of elements is given by @item_list_sz (also part of structure activity). Signed-off-by: Sebastien GODARD --- diff --git a/activity.c b/activity.c index 6eaedb3..1cc3b22 100644 --- a/activity.c +++ b/activity.c @@ -96,6 +96,7 @@ struct activity cpu_act = { .desc = "CPU utilization", #endif .name = "A_CPU", + .item_list_sz = 0, .g_nr = 1, .nr_ini = -1, .nr2 = 1, @@ -140,6 +141,7 @@ struct activity pcsw_act = { .desc = "Task creation and switching activity", #endif .name = "A_PCSW", + .item_list_sz = 0, .g_nr = 2, .nr_ini = 1, .nr2 = 1, @@ -184,6 +186,7 @@ struct activity irq_act = { .desc = "Interrupts statistics", #endif .name = "A_IRQ", + .item_list_sz = 0, .g_nr = 0, .nr_ini = -1, .nr2 = 1, @@ -228,6 +231,7 @@ struct activity swap_act = { .desc = "Swap activity", #endif .name = "A_SWAP", + .item_list_sz = 0, .g_nr = 1, .nr_ini = 1, .nr2 = 1, @@ -273,6 +277,7 @@ struct activity paging_act = { .desc = "Paging activity", #endif .name = "A_PAGE", + .item_list_sz = 0, .g_nr = 3, .nr_ini = 1, .nr2 = 1, @@ -317,6 +322,7 @@ struct activity io_act = { .desc = "I/O and transfer rate statistics", #endif .name = "A_IO", + .item_list_sz = 0, .g_nr = 2, .nr_ini = 1, .nr2 = 1, @@ -362,6 +368,7 @@ struct activity memory_act = { .desc = "Memory and/or swap utilization", #endif .name = "A_MEMORY", + .item_list_sz = 0, .g_nr = 9, .nr_ini = 1, .nr2 = 1, @@ -406,6 +413,7 @@ struct activity ktables_act = { .desc = "Kernel tables statistics", #endif .name = "A_KTABLES", + .item_list_sz = 0, .g_nr = 2, .nr_ini = 1, .nr2 = 1, @@ -450,6 +458,7 @@ struct activity queue_act = { .desc = "Queue length and load average statistics", #endif .name = "A_QUEUE", + .item_list_sz = 0, .g_nr = 3, .nr_ini = 1, .nr2 = 1, @@ -494,6 +503,7 @@ struct activity serial_act = { .desc = "TTY devices statistics", #endif .name = "A_SERIAL", + .item_list_sz = 0, .g_nr = 0, .nr_ini = -1, .nr2 = 1, @@ -538,6 +548,7 @@ struct activity disk_act = { .desc = "Block devices statistics", #endif .name = "A_DISK", + .item_list_sz = 0, .g_nr = 5, .nr_ini = -1, .nr2 = 1, @@ -582,6 +593,7 @@ struct activity net_dev_act = { .desc = "Network interfaces statistics", #endif .name = "A_NET_DEV", + .item_list_sz = 0, .g_nr = 4, .nr_ini = -1, .nr2 = 1, @@ -627,6 +639,7 @@ struct activity net_edev_act = { .desc = "Network interfaces errors statistics", #endif .name = "A_NET_EDEV", + .item_list_sz = 0, .g_nr = 4, .nr_ini = -1, .nr2 = 1, @@ -671,6 +684,7 @@ struct activity net_nfs_act = { .desc = "NFS client statistics", #endif .name = "A_NET_NFS", + .item_list_sz = 0, .g_nr = 3, .nr_ini = 1, .nr2 = 1, @@ -716,6 +730,7 @@ struct activity net_nfsd_act = { .desc = "NFS server statistics", #endif .name = "A_NET_NFSD", + .item_list_sz = 0, .g_nr = 5, .nr_ini = 1, .nr2 = 1, @@ -760,6 +775,7 @@ struct activity net_sock_act = { .desc = "IPv4 sockets statistics", #endif .name = "A_NET_SOCK", + .item_list_sz = 0, .g_nr = 2, .nr_ini = 1, .nr2 = 1, @@ -804,6 +820,7 @@ struct activity net_ip_act = { .desc = "IPv4 traffic statistics", #endif .name = "A_NET_IP", + .item_list_sz = 0, .g_nr = 3, .nr_ini = 1, .nr2 = 1, @@ -848,6 +865,7 @@ struct activity net_eip_act = { .desc = "IPv4 traffic errors statistics", #endif .name = "A_NET_EIP", + .item_list_sz = 0, .g_nr = 3, .nr_ini = 1, .nr2 = 1, @@ -893,6 +911,7 @@ struct activity net_icmp_act = { .desc = "ICMPv4 traffic statistics", #endif .name = "A_NET_ICMP", + .item_list_sz = 0, .g_nr = 4, .nr_ini = 1, .nr2 = 1, @@ -938,6 +957,7 @@ struct activity net_eicmp_act = { .desc = "ICMPv4 traffic errors statistics", #endif .name = "A_NET_EICMP", + .item_list_sz = 0, .g_nr = 6, .nr_ini = 1, .nr2 = 1, @@ -982,6 +1002,7 @@ struct activity net_tcp_act = { .desc = "TCPv4 traffic statistics", #endif .name = "A_NET_TCP", + .item_list_sz = 0, .g_nr = 2, .nr_ini = 1, .nr2 = 1, @@ -1026,6 +1047,7 @@ struct activity net_etcp_act = { .desc = "TCPv4 traffic errors statistics", #endif .name = "A_NET_ETCP", + .item_list_sz = 0, .g_nr = 2, .nr_ini = 1, .nr2 = 1, @@ -1070,6 +1092,7 @@ struct activity net_udp_act = { .desc = "UDPv4 traffic statistics", #endif .name = "A_NET_UDP", + .item_list_sz = 0, .g_nr = 2, .nr_ini = 1, .nr2 = 1, @@ -1114,6 +1137,7 @@ struct activity net_sock6_act = { .desc = "IPv6 sockets statistics", #endif .name = "A_NET_SOCK6", + .item_list_sz = 0, .g_nr = 1, .nr_ini = 1, .nr2 = 1, @@ -1159,6 +1183,7 @@ struct activity net_ip6_act = { .desc = "IPv6 traffic statistics", #endif .name = "A_NET_IP6", + .item_list_sz = 0, .g_nr = 4, .nr_ini = 1, .nr2 = 1, @@ -1204,6 +1229,7 @@ struct activity net_eip6_act = { .desc = "IPv6 traffic errors statistics", #endif .name = "A_NET_EIP6", + .item_list_sz = 0, .g_nr = 4, .nr_ini = 1, .nr2 = 1, @@ -1250,6 +1276,7 @@ struct activity net_icmp6_act = { .desc = "ICMPv6 traffic statistics", #endif .name = "A_NET_ICMP6", + .item_list_sz = 0, .g_nr = 5, .nr_ini = 1, .nr2 = 1, @@ -1295,6 +1322,7 @@ struct activity net_eicmp6_act = { .desc = "ICMPv6 traffic errors statistics", #endif .name = "A_NET_EICMP6", + .item_list_sz = 0, .g_nr = 6, .nr_ini = 1, .nr2 = 1, @@ -1339,6 +1367,7 @@ struct activity net_udp6_act = { .desc = "UDPv6 traffic statistics", #endif .name = "A_NET_UDP6", + .item_list_sz = 0, .g_nr = 2, .nr_ini = 1, .nr2 = 1, @@ -1383,6 +1412,7 @@ struct activity pwr_cpufreq_act = { .desc = "CPU clock frequency", #endif .name = "A_PWR_CPU", + .item_list_sz = 0, .g_nr = 1, .nr_ini = -1, .nr2 = 1, @@ -1427,6 +1457,7 @@ struct activity pwr_fan_act = { .desc = "Fans speed", #endif .name = "A_PWR_FAN", + .item_list_sz = 0, .g_nr = 1, .nr_ini = -1, .nr2 = 1, @@ -1471,6 +1502,7 @@ struct activity pwr_temp_act = { .desc = "Devices temperature", #endif .name = "A_PWR_TEMP", + .item_list_sz = 0, .g_nr = 2, .nr_ini = -1, .nr2 = 1, @@ -1515,6 +1547,7 @@ struct activity pwr_in_act = { .desc = "Voltage inputs statistics", #endif .name = "A_PWR_IN", + .item_list_sz = 0, .g_nr = 2, .nr_ini = -1, .nr2 = 1, @@ -1559,6 +1592,7 @@ struct activity huge_act = { .desc = "Huge pages utilization", #endif .name = "A_HUGE", + .item_list_sz = 0, .g_nr = 2, .nr_ini = 1, .nr2 = 1, @@ -1603,6 +1637,7 @@ struct activity pwr_wghfreq_act = { .desc = "CPU weighted frequency", #endif .name = "A_PWR_FREQ", + .item_list_sz = 0, .g_nr = 0, .nr_ini = -1, .nr2 = -1, @@ -1647,6 +1682,7 @@ struct activity pwr_usb_act = { .desc = "USB devices", #endif .name = "A_PWR_USB", + .item_list_sz = 0, .g_nr = 0, .nr_ini = -1, .nr2 = 1, @@ -1692,6 +1728,7 @@ struct activity filesystem_act = { .desc = "Filesystems statistics", #endif .name = "A_FS", + .item_list_sz = 0, .g_nr = 4, .nr_ini = -1, .nr2 = 1, @@ -1736,6 +1773,7 @@ struct activity fchost_act = { .desc = "Fibre Channel HBA statistics", #endif .name = "A_NET_FC", + .item_list_sz = 0, .g_nr = 2, .nr_ini = -1, .nr2 = 1, @@ -1781,6 +1819,7 @@ struct activity softnet_act = { .desc = "Software-based network processing statistics", #endif .name = "A_NET_SOFT", + .item_list_sz = 0, .g_nr = 2, .nr_ini = -1, .nr2 = 1, diff --git a/json_stats.c b/json_stats.c index 4310de7..b056b48 100644 --- a/json_stats.c +++ b/json_stats.c @@ -36,12 +36,6 @@ #endif extern unsigned int flags; -extern struct sa_dlist *st_iface_list; -extern struct sa_dlist *st_dev_list; -extern struct sa_dlist *st_fs_list; -extern int dlst_iface_idx; -extern int dlst_dev_idx; -extern int dlst_fs_idx; /* *************************************************************************** @@ -735,9 +729,9 @@ __print_funct_t json_print_disk_stats(struct activity *a, int curr, int tab, /* Get device name */ dev_name = get_sa_devname(sdc->major, sdc->minor, flags); - if (dlst_dev_idx) { + if (a->item_list != NULL) { /* A list of devices has been entered on the command line */ - if (!search_sa_dlist(st_dev_list, dlst_dev_idx, dev_name)) + if (!search_list_item(a->item_list, dev_name)) /* Device not found */ continue; } @@ -817,9 +811,9 @@ __print_funct_t json_print_net_dev_stats(struct activity *a, int curr, int tab, sndc = (struct stats_net_dev *) ((char *) a->buf[curr] + i * a->msize); - if (dlst_iface_idx) { + if (a->item_list != NULL) { /* A list of devices has been entered on the command line */ - if (!search_sa_dlist(st_iface_list, dlst_iface_idx, sndc->interface)) + if (!search_list_item(a->item_list, sndc->interface)) /* Device not found */ continue; } @@ -905,9 +899,9 @@ __print_funct_t json_print_net_edev_stats(struct activity *a, int curr, int tab, snedc = (struct stats_net_edev *) ((char *) a->buf[curr] + i * a->msize); - if (dlst_iface_idx) { + if (a->item_list != NULL) { /* A list of devices has been entered on the command line */ - if (!search_sa_dlist(st_iface_list, dlst_iface_idx, snedc->interface)) + if (!search_list_item(a->item_list, snedc->interface)) /* Device not found */ continue; } @@ -2177,10 +2171,10 @@ __print_funct_t json_print_filesystem_stats(struct activity *a, int curr, int ta for (i = 0; i < a->nr[curr]; i++) { sfc = (struct stats_filesystem *) ((char *) a->buf[curr] + i * a->msize); - if (dlst_fs_idx) { + if (a->item_list != NULL) { /* A list of devices has been entered on the command line */ - if (!search_sa_dlist(st_fs_list, dlst_fs_idx, - DISPLAY_MOUNT(a->opt_flags) ? sfc->mountp : sfc->fs_name)) + if (!search_list_item(a->item_list, + DISPLAY_MOUNT(a->opt_flags) ? sfc->mountp : sfc->fs_name)) /* Device not found */ continue; } diff --git a/pr_stats.c b/pr_stats.c index 986ad29..65dc259 100644 --- a/pr_stats.c +++ b/pr_stats.c @@ -40,12 +40,6 @@ extern unsigned int flags; extern int dis; extern char timestamp[][TIMESTAMP_LEN]; extern unsigned long avg_count; -extern struct sa_dlist *st_iface_list; -extern struct sa_dlist *st_dev_list; -extern struct sa_dlist *st_fs_list; -extern int dlst_iface_idx; -extern int dlst_dev_idx; -extern int dlst_fs_idx; /* *************************************************************************** @@ -1057,9 +1051,9 @@ __print_funct_t print_disk_stats(struct activity *a, int prev, int curr, /* Get device name */ dev_name = get_sa_devname(sdc->major, sdc->minor, flags); - if (dlst_dev_idx) { + if (a->item_list != NULL) { /* A list of devices has been entered on the command line */ - if (!search_sa_dlist(st_dev_list, dlst_dev_idx, dev_name)) + if (!search_list_item(a->item_list, dev_name)) /* Device not found */ continue; } @@ -1126,9 +1120,9 @@ __print_funct_t print_net_dev_stats(struct activity *a, int prev, int curr, for (i = 0; i < a->nr[curr]; i++) { sndc = (struct stats_net_dev *) ((char *) a->buf[curr] + i * a->msize); - if (dlst_iface_idx) { + if (a->item_list != NULL) { /* A list of devices has been entered on the command line */ - if (!search_sa_dlist(st_iface_list, dlst_iface_idx, sndc->interface)) + if (!search_list_item(a->item_list, sndc->interface)) /* Device not found */ continue; } @@ -1206,9 +1200,9 @@ __print_funct_t print_net_edev_stats(struct activity *a, int prev, int curr, for (i = 0; i < a->nr[curr]; i++) { snedc = (struct stats_net_edev *) ((char *) a->buf[curr] + i * a->msize); - if (dlst_iface_idx) { + if (a->item_list != NULL) { /* A list of devices has been entered on the command line */ - if (!search_sa_dlist(st_iface_list, dlst_iface_idx, snedc->interface)) + if (!search_list_item(a->item_list, snedc->interface)) /* Device not found */ continue; } @@ -2731,10 +2725,10 @@ __print_funct_t stub_print_filesystem_stats(struct activity *a, int prev, int cu for (i = 0; i < a->nr[curr]; i++) { sfc = (struct stats_filesystem *) ((char *) a->buf[curr] + i * a->msize); - if (dlst_fs_idx) { + if (a->item_list != NULL) { /* A list of devices has been entered on the command line */ - if (!search_sa_dlist(st_fs_list, dlst_fs_idx, - DISPLAY_MOUNT(a->opt_flags) ? sfc->mountp : sfc->fs_name)) + if (!search_list_item(a->item_list, + DISPLAY_MOUNT(a->opt_flags) ? sfc->mountp : sfc->fs_name)) /* Device not found */ continue; } diff --git a/raw_stats.c b/raw_stats.c index 8fe9856..6a9e0b2 100644 --- a/raw_stats.c +++ b/raw_stats.c @@ -29,12 +29,6 @@ #include "raw_stats.h" extern unsigned int flags; -extern struct sa_dlist *st_iface_list; -extern struct sa_dlist *st_dev_list; -extern struct sa_dlist *st_fs_list; -extern int dlst_iface_idx; -extern int dlst_dev_idx; -extern int dlst_fs_idx; /* *************************************************************************** @@ -536,9 +530,9 @@ __print_funct_t raw_print_disk_stats(struct activity *a, char *timestr, int curr /* Get device name */ dev_name = get_sa_devname(sdc->major, sdc->minor, flags); - if (dlst_dev_idx) { + if (a->item_list != NULL) { /* A list of devices has been entered on the command line */ - if (!search_sa_dlist(st_dev_list, dlst_dev_idx, dev_name)) + if (!search_list_item(a->item_list, dev_name)) /* Device not found */ continue; } @@ -595,9 +589,9 @@ __print_funct_t raw_print_net_dev_stats(struct activity *a, char *timestr, int c sndc = (struct stats_net_dev *) ((char *) a->buf[curr] + i * a->msize); - if (dlst_iface_idx) { + if (a->item_list != NULL) { /* A list of devices has been entered on the command line */ - if (!search_sa_dlist(st_iface_list, dlst_iface_idx, sndc->interface)) + if (!search_list_item(a->item_list, sndc->interface)) /* Device not found */ continue; } @@ -655,9 +649,9 @@ __print_funct_t raw_print_net_edev_stats(struct activity *a, char *timestr, int snedc = (struct stats_net_edev *) ((char *) a->buf[curr] + i * a->msize); - if (dlst_iface_idx) { + if (a->item_list != NULL) { /* A list of devices has been entered on the command line */ - if (!search_sa_dlist(st_iface_list, dlst_iface_idx, snedc->interface)) + if (!search_list_item(a->item_list, snedc->interface)) /* Device not found */ continue; } @@ -1488,10 +1482,10 @@ __print_funct_t raw_print_filesystem_stats(struct activity *a, char *timestr, in for (i = 0; i < a->nr[curr]; i++) { sfc = (struct stats_filesystem *) ((char *) a->buf[curr] + i * a->msize); - if (dlst_fs_idx) { + if (a->item_list != NULL) { /* A list of devices has been entered on the command line */ - if (!search_sa_dlist(st_fs_list, dlst_fs_idx, - DISPLAY_MOUNT(a->opt_flags) ? sfc->mountp : sfc->fs_name)) + if (!search_list_item(a->item_list, + DISPLAY_MOUNT(a->opt_flags) ? sfc->mountp : sfc->fs_name)) /* Device not found */ continue; } diff --git a/rd_stats.h b/rd_stats.h index 93bda7c..b24276f 100644 --- a/rd_stats.h +++ b/rd_stats.h @@ -18,6 +18,8 @@ #define IFNAMSIZ 16 #endif +/* Maximum length of block device name */ +#define MAX_DEV_LEN 128 /* Maximum length of network interface name */ #define MAX_IFACE_LEN IFNAMSIZ /* Maximum length of USB manufacturer string */ diff --git a/rndr_stats.c b/rndr_stats.c index 6954191..b6889fe 100644 --- a/rndr_stats.c +++ b/rndr_stats.c @@ -38,12 +38,6 @@ char *seps[] = {"\t", ";"}; extern unsigned int flags; -extern struct sa_dlist *st_iface_list; -extern struct sa_dlist *st_dev_list; -extern struct sa_dlist *st_fs_list; -extern int dlst_iface_idx; -extern int dlst_dev_idx; -extern int dlst_fs_idx; /* *************************************************************************** @@ -1085,9 +1079,9 @@ __print_funct_t render_disk_stats(struct activity *a, int isdb, char *pre, /* Get device name */ dev_name = get_sa_devname(sdc->major, sdc->minor, flags); - if (dlst_dev_idx) { + if (a->item_list != NULL) { /* A list of devices has been entered on the command line */ - if (!search_sa_dlist(st_dev_list, dlst_dev_idx, dev_name)) + if (!search_list_item(a->item_list, dev_name)) /* Device not found */ continue; } @@ -1180,9 +1174,9 @@ __print_funct_t render_net_dev_stats(struct activity *a, int isdb, char *pre, sndc = (struct stats_net_dev *) ((char *) a->buf[curr] + i * a->msize); - if (dlst_iface_idx) { + if (a->item_list != NULL) { /* A list of devices has been entered on the command line */ - if (!search_sa_dlist(st_iface_list, dlst_iface_idx, sndc->interface)) + if (!search_list_item(a->item_list, sndc->interface)) /* Device not found */ continue; } @@ -1283,9 +1277,9 @@ __print_funct_t render_net_edev_stats(struct activity *a, int isdb, char *pre, snedc = (struct stats_net_edev *) ((char *) a->buf[curr] + i * a->msize); - if (dlst_iface_idx) { + if (a->item_list != NULL) { /* A list of devices has been entered on the command line */ - if (!search_sa_dlist(st_iface_list, dlst_iface_idx, snedc->interface)) + if (!search_list_item(a->item_list, snedc->interface)) /* Device not found */ continue; } @@ -2897,10 +2891,10 @@ __print_funct_t render_filesystem_stats(struct activity *a, int isdb, char *pre, for (i = 0; i < a->nr[curr]; i++) { sfc = (struct stats_filesystem *) ((char *) a->buf[curr] + i * a->msize); - if (dlst_fs_idx) { + if (a->item_list != NULL) { /* A list of devices has been entered on the command line */ - if (!search_sa_dlist(st_fs_list, dlst_fs_idx, - DISPLAY_MOUNT(a->opt_flags) ? sfc->mountp : sfc->fs_name)) + if (!search_list_item(a->item_list, + DISPLAY_MOUNT(a->opt_flags) ? sfc->mountp : sfc->fs_name)) /* Device not found */ continue; } diff --git a/sa.h b/sa.h index b0dbb6f..f2609f1 100644 --- a/sa.h +++ b/sa.h @@ -313,7 +313,6 @@ struct svg_parm { int graph_no; /* Total number of views already displayed */ int restart; /* TRUE if we have just met a RESTART record */ int nr_act_dispd; /* Number of activities that will be displayed */ - __nr_t nr_max; /* Maximum number of items for this activity */ struct file_header *file_hdr; /* Pointer on file header structure */ }; @@ -690,6 +689,11 @@ struct record_header { * Indicate that this activity may have sub-items. */ #define AO_MATRIX 0x80 +/* + * Indicate that a list of devices has been entered on the command + * line for this activity (see options --dev=, --iface=, ...) + */ +#define AO_LIST_ON_CMDLINE 0x100 #define IS_COLLECTED(m) (((m) & AO_COLLECTED) == AO_COLLECTED) #define IS_SELECTED(m) (((m) & AO_SELECTED) == AO_SELECTED) @@ -699,6 +703,7 @@ struct record_header { #define HAS_MULTIPLE_OUTPUTS(m) (((m) & AO_MULTIPLE_OUTPUTS) == AO_MULTIPLE_OUTPUTS) #define ONE_GRAPH_PER_ITEM(m) (((m) & AO_GRAPH_PER_ITEM) == AO_GRAPH_PER_ITEM) #define IS_MATRIX(m) (((m) & AO_MATRIX) == AO_MATRIX) +#define HAS_LIST_ON_CMDLINE(m) (((m) & AO_LIST_ON_CMDLINE) == AO_LIST_ON_CMDLINE) #define _buf0 buf[0] #define _nr0 nr[0] @@ -807,9 +812,16 @@ struct activity { */ __nr_t (*f_count_new) (struct activity *, int); /* - * Linked list containing all the different items found. Used by sadf. + * Linked list containing item names. This is either all the different items + * found in a file for activities that have a @f_count_function() (used by sadf), + * or a list entered on the command line (used by sadf and sar). */ - void *item_list; + struct sa_item *item_list; + /* + * Number of different items found in file (calculated by sadf). + * This is also the number of items in @item_list if this list exists. + */ + __nr_t item_list_sz; /* * Header string displayed by sadf -d. * Header lines for each output (for activities with multiple outputs) are @@ -1120,14 +1132,12 @@ struct tstamp { int use; }; -/* List of devices entered on the command line */ -struct sa_dlist { - /* Device name */ - char dev_name[MAX_NAME_LEN]; +/* Structure for items in list */ +struct sa_item { + char *item_name; + struct sa_item *next; }; -#define SA_DLIST_SIZE (sizeof(struct sa_dlist)) - /* *************************************************************************** @@ -1272,6 +1282,8 @@ void print_collect_error (void); #ifndef SOURCE_SADC +int add_list_item + (struct sa_item **, char *, int); void allocate_bitmaps (struct activity * []); void allocate_structures @@ -1312,7 +1324,7 @@ void get_itv_value int next_slice (unsigned long long, unsigned long long, int, long); void parse_sa_devices - (char *, struct sa_dlist **, int *, int *, int); + (char *, struct activity *, int, int *, int); int parse_sar_opt (char * [], int *, struct activity * [], unsigned int *, int); int parse_sar_I_opt @@ -1354,8 +1366,8 @@ int sa_get_record_timestamp_struct (unsigned int, struct record_header *, struct tm *, struct tm *); int sa_open_read_magic (int *, char *, struct file_magic *, int, int *, int); -int search_sa_dlist - (struct sa_dlist *, int, char *); +int search_list_item + (struct sa_item *, char *); void select_all_activities (struct activity * []); void select_default_activity diff --git a/sa_common.c b/sa_common.c index d42f625..83c6ee9 100644 --- a/sa_common.c +++ b/sa_common.c @@ -124,52 +124,6 @@ int get_activity_nr(struct activity *act[], unsigned int option, int count_outpu return n; } -/* - *************************************************************************** - * Allocate structures for devices entered on the command line. - * - * IN: - * @nr_alloc_slots Number of slots to allocate. - * @nr_used_slots Number of slots currently used. - * - * OUT: - * @st_list Address of allocated structures. - *************************************************************************** - */ -void salloc_sa_dlist(struct sa_dlist **st_list, int nr_alloc_slots, int nr_used_slots) -{ - if (nr_alloc_slots) { - SREALLOC(*st_list, struct sa_dlist, sizeof(struct sa_dlist) * (nr_used_slots + nr_alloc_slots)); - } -} - -/* - *************************************************************************** - * Look for device in list. - * - * IN: - * @st_list Structure where devices are saved. - * @dlst_idx Number of devices in the list. - * @d_name Device name to look for. - * - * RETURNS: - * 1 if device found in list, 0 otherwise. - *************************************************************************** - */ -int search_sa_dlist(struct sa_dlist *st_list, int dlst_idx, char *d_name) -{ - int i; - struct sa_dlist *st_list_i; - - for (i = 0; i < dlst_idx; i++) { - st_list_i = st_list + i; - if (!strcmp(st_list_i->dev_name, d_name)) - return 1; - } - - return 0; -} - /* *************************************************************************** * Look for the most recent of saDD and saYYYYMMDD to decide which one to @@ -2467,34 +2421,95 @@ int count_csval_arg(char *arg_v) /* *************************************************************************** - * Parse devices entered on the command line. + * Look for item in list. + * + * IN: + * @list Pointer on the start of the linked list. + * @item_name Item name to look for. + * + * RETURNS: + * 1 if item found in list, 0 otherwise. + *************************************************************************** + */ +int search_list_item(struct sa_item *list, char *item_name) +{ + while (list != NULL) { + if (!strcmp(list->item_name, item_name)) + return 1; /* Item found in list */ + list = list->next; + } + + /* Item not found */ + return 0; +} + +/* + *************************************************************************** + * Add item to the list. + * + * IN: + * @list Address of pointer on the start of the linked list. + * @item_name Name of the item. + * @max_len Max length of an item. + * + * RETURNS: + * 1 if item has been added to the list (since it was not previously there), + * and 0 otherwise (item already in list or item name too long). + *************************************************************************** + */ +int add_list_item(struct sa_item **list, char *item_name, int max_len) +{ + struct sa_item *e; + int len; + + if ((len = strnlen(item_name, max_len)) == max_len) + /* Item too long */ + return 0; + + while (*list != NULL) { + e = *list; + if (!strcmp(e->item_name, item_name)) + return 0; /* Item found in list */ + list = &(e->next); + } + + /* Item not found: Add it to the list */ + SREALLOC(*list, struct sa_item, sizeof(struct sa_item)); + e = *list; + if ((e->item_name = (unsigned char *) malloc(len + 1)) == NULL) { + perror("malloc"); + exit(4); + } + strcpy(e->item_name, item_name); + + return 1; +} + +/* + *************************************************************************** + * Parse devices entered on the command line and save them in activity's + * list. * * IN: * @argv Argument with list of devices. - * @st_list Structure where devices will be saved. - * @dlst_idx Number of devices previously saved in the list. + * @a Activity for which devices are entered on the command line. + * @max_len Max length of a device name. * @opt Index in list of arguments. * @pos Position is string where is located the first device. * * OUT: - * @st_list Structure where devices have been saved. - * @dlst_idx Total number of devices saved in the list. * @opt Index on next argument. *************************************************************************** */ -void parse_sa_devices(char *argv, struct sa_dlist **st_list, - int *dlst_idx, int *opt, int pos) +void parse_sa_devices(char *argv, struct activity *a, int max_len, int *opt, int pos) { char *t; - struct sa_dlist *st_list_i; - - /* (Re)allocate device list */ - salloc_sa_dlist(st_list, count_csval_arg(argv + pos), *dlst_idx); for (t = strtok(argv + pos, ","); t; t = strtok(NULL, ",")) { - st_list_i = *st_list + (*dlst_idx)++; - strncpy(st_list_i->dev_name, t, MAX_NAME_LEN - 1); - st_list_i->dev_name[MAX_NAME_LEN - 1] = '\0'; + a->item_list_sz += add_list_item(&(a->item_list), t, max_len); + } + if (a->item_list_sz) { + a->options |= AO_LIST_ON_CMDLINE; } (*opt)++; } diff --git a/sadf.c b/sadf.c index 55e4144..a8243e2 100644 --- a/sadf.c +++ b/sadf.c @@ -67,9 +67,6 @@ struct file_header file_hdr; */ unsigned int id_seq[NR_ACT]; -/* Maximum number of items for each activity */ -__nr_t id_nr_max[NR_ACT]; - /* Current record header */ struct record_header record_hdr[3]; @@ -77,10 +74,6 @@ struct record_header record_hdr[3]; struct tstamp tm_start, tm_end; char *args[MAX_ARGV_NR]; -/* Devices entered on the command line */ -struct sa_dlist *st_iface_list = NULL, *st_dev_list = NULL, *st_fs_list = NULL; -int dlst_iface_idx = 0, dlst_dev_idx = 0, dlst_fs_idx = 0; - extern struct activity *act[]; extern struct report_format *fmt[]; @@ -428,52 +421,39 @@ void seek_file_position(int ifd, int action) /* *************************************************************************** - * Compute the number of rows that will contain SVG views. Usually only one - * view is displayed on a row, unless the "packed" option has been entered. - * Each activity selected may have several views. Moreover some activities - * may have a number of items that vary within the file: In this case, - * the number of views will depend on the highest number of items saved in - * the file. + * Count number of different items in file. Save these numbers in fields + * @item_list_sz of structure activity, and create the corresponding list + * in field @item_list. * * IN: - * @ifd File descriptor of input file. - * @file Name of file being read. - * @file_magic file_magic structure filled with file magic header data. - * @file_actlst List of (known or unknown) activities in file. - * @rectime Structure where timestamp (expressed in local time or - * in UTC depending on whether options -T/-t have been - * used or not) can be saved for current record. - * @loctime Structure where timestamp (expressed in local time) - * can be saved for current record. - * @views_per_row Default number of views displayed on a single row. - * - * OUT: - * @views_per_row Maximum number of views that will be displayed on a - * single row (useful only if "packed" option entered). - * @nr_act_dispd Number of activities that will be displayed. - * May be 0. + * @ifd File descriptor of input file. + * @file Name of file being read. + * @file_magic file_magic structure filled with file magic header data. + * @file_actlst List of (known or unknown) activities in file. + * @rectime Structure where timestamp (expressed in local time or + * in UTC depending on whether options -T/-t have been + * used or not) can be saved for current record. + * @loctime Structure where timestamp (expressed in local time) + * can be saved for current record. * * RETURNS: - * Number of rows containing views, taking into account only activities - * to be displayed, and selected period of time (options -s/-e). - * Result may be 0. + * 0 if no records are concerned in file, and 1 otherwise. *************************************************************************** */ -int get_svg_graph_nr(int ifd, char *file, struct file_magic *file_magic, - struct file_activity *file_actlst, struct tm *rectime, - struct tm *loctime, int *views_per_row, int *nr_act_dispd) +int count_file_items(int ifd, char *file, struct file_magic *file_magic, + struct file_activity *file_actlst, struct tm *rectime, + struct tm *loctime) { - int i, n, p, eosaf; - int rtype, tot_g_nr = 0; - - *nr_act_dispd = 0; + int i, eosaf, rtype; /* Save current file position */ seek_file_position(ifd, DO_SAVE); /* Init maximum number of items for each activity */ for (i = 0; i < NR_ACT; i++) { - id_nr_max[i] = 0; + if (!HAS_LIST_ON_CMDLINE(act[i]->options)) { + act[i]->item_list_sz = 0; + } } /* Look for the first record that will be displayed */ @@ -482,7 +462,7 @@ int get_svg_graph_nr(int ifd, char *file, struct file_magic *file_magic, 0, file, &rtype, 0, file_magic, file_actlst, rectime, loctime); if (eosaf) - /* No record to display => no graph too */ + /* No record to display */ return 0; } while ((tm_start.use && (datecmp(loctime, &tm_start) < 0)) || @@ -494,11 +474,13 @@ int get_svg_graph_nr(int ifd, char *file, struct file_magic *file_magic, */ do { for (i = 0; i < NR_ACT; i++) { - if (act[i]->f_count_new) { - id_nr_max[i] += (*act[i]->f_count_new)(act[i], 0); - } - else if (act[i]->nr[0] > id_nr_max[i]) { - id_nr_max[i] = act[i]->nr[0]; + if (!HAS_LIST_ON_CMDLINE(act[i]->options)) { + if (act[i]->f_count_new) { + act[i]->item_list_sz += (*act[i]->f_count_new)(act[i], 0); + } + else if (act[i]->nr[0] > act[i]->item_list_sz) { + act[i]->item_list_sz = act[i]->nr[0]; + } } } @@ -515,6 +497,58 @@ int get_svg_graph_nr(int ifd, char *file, struct file_magic *file_magic, } while (!eosaf && !(tm_end.use && (datecmp(loctime, &tm_end) >= 0))); + /* Rewind file */ + seek_file_position(ifd, DO_RESTORE); + + return 1; +} + +/* + *************************************************************************** + * Compute the number of rows that will contain SVG views. Usually only one + * view is displayed on a row, unless the "packed" option has been entered. + * Each activity selected may have several views. Moreover some activities + * may have a number of items that vary within the file: In this case, + * the number of views will depend on the highest number of items saved in + * the file. + * + * IN: + * @ifd File descriptor of input file. + * @file Name of file being read. + * @file_magic file_magic structure filled with file magic header data. + * @file_actlst List of (known or unknown) activities in file. + * @rectime Structure where timestamp (expressed in local time or + * in UTC depending on whether options -T/-t have been + * used or not) can be saved for current record. + * @loctime Structure where timestamp (expressed in local time) + * can be saved for current record. + * @views_per_row Default number of views displayed on a single row. + * + * OUT: + * @views_per_row Maximum number of views that will be displayed on a + * single row (useful only if "packed" option entered). + * @nr_act_dispd Number of activities that will be displayed. + * May be 0. + * + * RETURNS: + * Number of rows containing views, taking into account only activities + * to be displayed, and selected period of time (options -s/-e). + * Result may be 0. + *************************************************************************** + */ +int get_svg_graph_nr(int ifd, char *file, struct file_magic *file_magic, + struct file_activity *file_actlst, struct tm *rectime, + struct tm *loctime, int *views_per_row, int *nr_act_dispd) +{ + int i, n, p, tot_g_nr = 0; + + *nr_act_dispd = 0; + + /* Count items in file */ + if (!count_file_items(ifd, file, file_magic, file_actlst, rectime, loctime)) + /* No record to display => No graph */ + return 0; + for (i = 0; i < NR_ACT; i++) { if (!id_seq[i]) continue; @@ -525,19 +559,6 @@ int get_svg_graph_nr(int ifd, char *file, struct file_magic *file_magic, (*nr_act_dispd)++; - if (((act[p]->id == A_NET_DEV) || (act[p]->id == A_NET_EDEV)) && - (dlst_iface_idx > 0) && (dlst_iface_idx < id_nr_max[p])) { - id_nr_max[p] = dlst_iface_idx; - } - if ((act[p]->id == A_DISK) && - (dlst_dev_idx > 0) && (dlst_dev_idx < id_nr_max[p])) { - id_nr_max[p] = dlst_dev_idx; - } - if ((act[p]->id == A_FS) && - (dlst_fs_idx > 0) && (dlst_fs_idx < id_nr_max[p])) { - id_nr_max[p] = dlst_fs_idx; - } - if (PACK_VIEWS(flags)) { /* * One activity = one row with multiple views. @@ -558,7 +579,7 @@ int get_svg_graph_nr(int ifd, char *file, struct file_magic *file_magic, n = act[p]->g_nr; } if (ONE_GRAPH_PER_ITEM(act[p]->options)) { - n = n * id_nr_max[p]; + n = n * act[p]->item_list_sz; } if (act[p]->g_nr > *views_per_row) { *views_per_row = act[p]->g_nr; @@ -567,9 +588,6 @@ int get_svg_graph_nr(int ifd, char *file, struct file_magic *file_magic, tot_g_nr += n; } - /* Rewind file */ - seek_file_position(ifd, DO_RESTORE); - if (*views_per_row > MAX_VIEWS_ON_A_ROW) { *views_per_row = MAX_VIEWS_ON_A_ROW; } @@ -883,7 +901,6 @@ void display_curr_act_graphs(int ifd, int *curr, long *cnt, int *eosaf, parm.ust_time_first = record_hdr[2].ust_time; parm.restart = TRUE; parm.file_hdr = &file_hdr; - parm.nr_max = id_nr_max[p]; parm.nr_act_dispd = nr_act_dispd; *cnt = count; @@ -1425,7 +1442,7 @@ int main(int argc, char **argv) { int opt = 1, sar_options = 0; int day_offset = 0; - int i, rc; + int i, rc, p, q; char dfile[MAX_FILE_LEN]; char *t, *v; @@ -1467,20 +1484,24 @@ int main(int argc, char **argv) else if (!strncmp(argv[opt], "--dev=", 6)) { /* Parse devices entered on the command line */ - parse_sa_devices(argv[opt], &st_dev_list, - &dlst_dev_idx, &opt, 6); + p = get_activity_position(act, A_DISK, EXIT_IF_NOT_FOUND); + parse_sa_devices(argv[opt], act[p], MAX_DEV_LEN, &opt, 6); } else if (!strncmp(argv[opt], "--fs=", 5)) { /* Parse devices entered on the command line */ - parse_sa_devices(argv[opt], &st_fs_list, - &dlst_fs_idx, &opt, 5); + p = get_activity_position(act, A_FS, EXIT_IF_NOT_FOUND); + parse_sa_devices(argv[opt], act[p], MAX_FS_LEN, &opt, 5); } else if (!strncmp(argv[opt], "--iface=", 8)) { /* Parse devices entered on the command line */ - parse_sa_devices(argv[opt], &st_iface_list, - &dlst_iface_idx, &opt, 8); + p = get_activity_position(act, A_NET_DEV, EXIT_IF_NOT_FOUND); + parse_sa_devices(argv[opt], act[p], MAX_IFACE_LEN, &opt, 8); + q = get_activity_position(act, A_NET_EDEV, EXIT_IF_NOT_FOUND); + act[q]->item_list = act[p]->item_list; + act[q]->item_list_sz = act[p]->item_list_sz; + act[q]->options |= AO_LIST_ON_CMDLINE; } else if (!strcmp(argv[opt], "-s")) { diff --git a/sadf.h b/sadf.h index bf00961..558aef2 100644 --- a/sadf.h +++ b/sadf.h @@ -116,27 +116,6 @@ #define TEST_MARKUP(m) (((m) & FO_TEST_MARKUP) == FO_TEST_MARKUP) #define REJECT_TRUE_TIME(m) (((m) & FO_NO_TRUE_TIME) == FO_NO_TRUE_TIME) -/* Structure for items in list */ -struct interface_lst { - char name[MAX_IFACE_LEN]; - struct interface_lst *next; -}; - -struct filesystem_lst { - char name[MAX_FS_LEN]; - struct filesystem_lst *next; -}; - -struct fchost_lst { - char name[MAX_FCH_LEN]; - struct fchost_lst *next; -}; - -struct disk_lst { - int major; - int minor; - struct disk_lst *next; -}; /* *************************************************************************** diff --git a/sadf_misc.c b/sadf_misc.c index 289edb6..4684c78 100644 --- a/sadf_misc.c +++ b/sadf_misc.c @@ -1018,29 +1018,12 @@ __printf_funct_t print_svg_header(void *parm, int action, char *dfile, __nr_t count_new_net_dev(struct activity *a, int curr) { int i, nr = 0; - struct interface_lst *e, **p; struct stats_net_dev *sndc; for (i = 0; i < a->nr[curr]; i++) { sndc = (struct stats_net_dev *) ((char *) a->buf[curr] + i * a->msize); - p = (struct interface_lst **) &(a->item_list); - while (*p != NULL) { - e = *p; - if (!strcmp(e->name, sndc->interface)) - break; /* Item found */ - p = &(e->next); - } - if (*p == NULL) { - /* - * Item not found: Increment total number - * of new items found and add it to the list. - */ - nr++; - SREALLOC(*p, struct interface_lst, sizeof(struct interface_lst)); - e = *p; - strcpy(e->name, sndc->interface); - } + nr += add_list_item(&(a->item_list), sndc->interface, MAX_IFACE_LEN); } return nr; @@ -1064,29 +1047,12 @@ __nr_t count_new_net_dev(struct activity *a, int curr) __nr_t count_new_net_edev(struct activity *a, int curr) { int i, nr = 0; - struct interface_lst *e, **p; struct stats_net_edev *snedc; for (i = 0; i < a->nr[curr]; i++) { snedc = (struct stats_net_edev *) ((char *) a->buf[curr] + i * a->msize); - p = (struct interface_lst **) &(a->item_list); - while (*p != NULL) { - e = *p; - if (!strcmp(e->name, snedc->interface)) - break; /* Item found */ - p = &(e->next); - } - if (*p == NULL) { - /* - * Item not found: Increment total number - * of new items found and add it to the list. - */ - nr++; - SREALLOC(*p, struct interface_lst, sizeof(struct interface_lst)); - e = *p; - strcpy(e->name, snedc->interface); - } + nr += add_list_item(&(a->item_list), snedc->interface, MAX_IFACE_LEN); } return nr; @@ -1110,29 +1076,12 @@ __nr_t count_new_net_edev(struct activity *a, int curr) __nr_t count_new_filesystem(struct activity *a, int curr) { int i, nr = 0; - struct filesystem_lst *e, **p; struct stats_filesystem *sfc; for (i = 0; i < a->nr[curr]; i++) { sfc = (struct stats_filesystem *) ((char *) a->buf[curr] + i * a->msize); - p = (struct filesystem_lst **) &(a->item_list); - while (*p != NULL) { - e = *p; - if (!strcmp(e->name, sfc->fs_name)) - break; /* Item found */ - p = &(e->next); - } - if (*p == NULL) { - /* - * Item not found: Increment total number - * of new items found and add it to the list. - */ - nr++; - SREALLOC(*p, struct filesystem_lst, sizeof(struct filesystem_lst)); - e = *p; - strcpy(e->name, sfc->fs_name); - } + nr += add_list_item(&(a->item_list), sfc->fs_name, MAX_FS_LEN); } return nr; @@ -1156,29 +1105,12 @@ __nr_t count_new_filesystem(struct activity *a, int curr) __nr_t count_new_fchost(struct activity *a, int curr) { int i, nr = 0; - struct fchost_lst *e, **p; struct stats_fchost *sfcc; for (i = 0; i < a->nr[curr]; i++) { sfcc = (struct stats_fchost *) ((char *) a->buf[curr] + i * a->msize); - p = (struct fchost_lst **) &(a->item_list); - while (*p != NULL) { - e = *p; - if (!strcmp(e->name, sfcc->fchost_name)) - break; /* Item found */ - p = &(e->next); - } - if (*p == NULL) { - /* - * Item not found: Increment total number - * of new items found and add it to the list. - */ - nr++; - SREALLOC(*p, struct fchost_lst, sizeof(struct fchost_lst)); - e = *p; - strcpy(e->name, sfcc->fchost_name); - } + nr += add_list_item(&(a->item_list), sfcc->fchost_name, MAX_FCH_LEN); } return nr; @@ -1202,30 +1134,14 @@ __nr_t count_new_fchost(struct activity *a, int curr) __nr_t count_new_disk(struct activity *a, int curr) { int i, nr = 0; - struct disk_lst *e, **p; struct stats_disk *sdc; for (i = 0; i < a->nr[curr]; i++) { sdc = (struct stats_disk *) ((char *) a->buf[curr] + i * a->msize); - p = (struct disk_lst **) &(a->item_list); - while (*p != NULL) { - e = *p; - if ((e->major == sdc->major) && (e->minor == sdc->minor)) - break; /* Item found */ - p = &(e->next); - } - if (*p == NULL) { - /* - * Item not found: Increment total number - * of new items found and add it to the list. - */ - nr++; - SREALLOC(*p, struct disk_lst, sizeof(struct disk_lst)); - e = *p; - e->major = sdc->major; - e->minor = sdc->minor; - } + nr += add_list_item(&(a->item_list), + get_sa_devname(sdc->major, sdc->minor, flags), + MAX_DEV_LEN); } return nr; diff --git a/sar.c b/sar.c index 0634ff7..f2e4306 100644 --- a/sar.c +++ b/sar.c @@ -76,10 +76,6 @@ struct record_header record_hdr[3]; */ unsigned int id_seq[NR_ACT]; -/* Devices entered on the command line */ -struct sa_dlist *st_iface_list = NULL, *st_dev_list = NULL, *st_fs_list = NULL; -int dlst_iface_idx = 0, dlst_dev_idx = 0, dlst_fs_idx = 0; - struct tm rectime; /* Contain the date specified by -s and -e options */ @@ -1242,7 +1238,7 @@ void read_stats(void) */ int main(int argc, char **argv) { - int i, rc, opt = 1, args_idx = 1; + int i, rc, opt = 1, args_idx = 1, p, q; int fd[2]; int day_offset = 0; char from_file[MAX_FILE_LEN], to_file[MAX_FILE_LEN]; @@ -1278,20 +1274,24 @@ int main(int argc, char **argv) else if (!strncmp(argv[opt], "--dev=", 6)) { /* Parse devices entered on the command line */ - parse_sa_devices(argv[opt], &st_dev_list, - &dlst_dev_idx, &opt, 6); + p = get_activity_position(act, A_DISK, EXIT_IF_NOT_FOUND); + parse_sa_devices(argv[opt], act[p], MAX_DEV_LEN, &opt, 6); } else if (!strncmp(argv[opt], "--fs=", 5)) { /* Parse devices entered on the command line */ - parse_sa_devices(argv[opt], &st_fs_list, - &dlst_fs_idx, &opt, 5); + p = get_activity_position(act, A_FS, EXIT_IF_NOT_FOUND); + parse_sa_devices(argv[opt], act[p], MAX_FS_LEN, &opt, 5); } else if (!strncmp(argv[opt], "--iface=", 8)) { /* Parse devices entered on the command line */ - parse_sa_devices(argv[opt], &st_iface_list, - &dlst_iface_idx, &opt, 8); + p = get_activity_position(act, A_NET_DEV, EXIT_IF_NOT_FOUND); + parse_sa_devices(argv[opt], act[p], MAX_IFACE_LEN, &opt, 8); + q = get_activity_position(act, A_NET_EDEV, EXIT_IF_NOT_FOUND); + act[q]->item_list = act[p]->item_list; + act[q]->item_list_sz = act[p]->item_list_sz; + act[q]->options |= AO_LIST_ON_CMDLINE; } else if (!strcmp(argv[opt], "--help")) { diff --git a/svg_stats.c b/svg_stats.c index 750a71a..27314e3 100644 --- a/svg_stats.c +++ b/svg_stats.c @@ -38,12 +38,6 @@ #endif extern unsigned int flags; -extern struct sa_dlist *st_iface_list; -extern struct sa_dlist *st_dev_list; -extern struct sa_dlist *st_fs_list; -extern int dlst_iface_idx; -extern int dlst_dev_idx; -extern int dlst_fs_idx; unsigned int svg_colors[] = {0x00cc00, 0xff00bf, 0x00ffff, 0xff0000, 0xe85f00, 0x0000ff, 0x006020, 0x7030a0, @@ -267,53 +261,6 @@ char **allocate_graph_lines(int n, int **outsize, double **spmin, double **spmax return out; } -/* - *************************************************************************** - * Reallocate all the arrays used to save graphs data, min and max values. - * The new size is the double of the original one. - * - * IN: - * @n Number of slots currently allocated. - * @out Current pointer on arrays containing the graphs data. - * @outsize Current pointer on array containing the size of each element - * in array of chars. - * @spmin Current pointer on array containing min values. - * @spmax Current pointer on array containing max values. - * - * OUT: - * @out New pointer on arrays containing the graphs data. - * @outsize New pointer on array containing the size of each element - * in array of chars. - * @spmin New pointer on array containing min values. - * @spmax New pointer on array containing max values. - *************************************************************************** - */ -void reallocate_all_graph_lines(int n, char ***out, int **outsize, - double **spmin, double **spmax) -{ - char *out_p; - int i; - - /* Reallocate all the arrays */ - SREALLOC(*out, char *, n * sizeof(char *) * 2); - SREALLOC(*outsize, int, n * sizeof(int) * 2); - SREALLOC(*spmin, double, n * sizeof(double) * 2); - SREALLOC(*spmax, double, n * sizeof(double) * 2); - - /* Allocate arrays of chars that will contain graphs data for the newly allocated slots */ - for (i = 0; i < n; i++) { - if ((out_p = (char *) malloc(CHUNKSIZE * sizeof(char))) == NULL) { - perror("malloc"); - exit(4); - } - *(*out + n + i) = out_p; - *out_p = '\0'; - *(*outsize + n + i) = CHUNKSIZE; - *(*spmin + n + i) = DBL_MAX; - *(*spmax + n + i) = -DBL_MAX; - } -} - /* *************************************************************************** * Save SVG code for current graph. @@ -1109,7 +1056,7 @@ __print_funct_t svg_print_cpu_stats(struct activity *a, int curr, int action, st * Allocate arrays that will contain the graphs data * and the min/max values. */ - out = allocate_graph_lines(10 * svg_p->nr_max, &outsize, &spmin, &spmax); + out = allocate_graph_lines(10 * a->item_list_sz, &outsize, &spmin, &spmax); } if (action & F_MAIN) { @@ -1308,7 +1255,7 @@ __print_funct_t svg_print_cpu_stats(struct activity *a, int curr, int action, st group2[0]++; } - for (i = 0; (i < svg_p->nr_max) && (i < a->bitmap->b_size + 1); i++) { + for (i = 0; (i < a->item_list_sz) && (i < a->bitmap->b_size + 1); i++) { /* Should current CPU (including CPU "all") be displayed? */ if (!(a->bitmap->b_array[i >> 3] & (1 << (i & 0x07)))) @@ -2087,7 +2034,7 @@ __print_funct_t svg_print_disk_stats(struct activity *a, int curr, int action, s * outsize + 8 will contain a positive value (TRUE) if the device * has either still not been registered, or has been unregistered. */ - out = allocate_graph_lines(9 * svg_p->nr_max, &outsize, &spmin, &spmax); + out = allocate_graph_lines(9 * a->item_list_sz, &outsize, &spmin, &spmax); } if (action & F_MAIN) { @@ -2097,7 +2044,7 @@ __print_funct_t svg_print_disk_stats(struct activity *a, int curr, int action, s * Mark previously registered devices as now * possibly unregistered for all graphs. */ - for (k = 0; k < svg_p->nr_max; k++) { + for (k = 0; k < a->item_list_sz; k++) { unregistered = outsize + k * 9 + 8; if (*unregistered == FALSE) { *unregistered = MAYBE; @@ -2111,31 +2058,33 @@ __print_funct_t svg_print_disk_stats(struct activity *a, int curr, int action, s /* Get device name */ item_name = get_sa_devname(sdc->major, sdc->minor, flags); - if (dlst_dev_idx) { + if (a->item_list != NULL) { /* A list of devices has been entered on the command line */ - if (!search_sa_dlist(st_dev_list, dlst_dev_idx, item_name)) + if (!search_list_item(a->item_list, item_name)) /* Device not found */ continue; } /* Look for corresponding graph */ - for (k = 0; k < svg_p->nr_max; k++) { + for (k = 0; k < a->item_list_sz; k++) { if ((sdc->major == *(spmax + k * 9 + 8)) && (sdc->minor == *(spmin + k * 9 + 8))) /* Graph found! */ break; } - if (k == svg_p->nr_max) { + if (k == a->item_list_sz) { /* Graph not found: Look for first free entry */ - for (k = 0; k < svg_p->nr_max; k++) { + for (k = 0; k < a->item_list_sz; k++) { if (*(spmax + k * 9 + 8) == -DBL_MAX) break; } - if (k == svg_p->nr_max) { - /* No free graph entry: Extend all buffers */ - reallocate_all_graph_lines(9 * svg_p->nr_max, - &out, &outsize, &spmin, &spmax); - svg_p->nr_max *= 2; + if (k == a->item_list_sz) { + /* No free graph entry: Ignore it (should never happen) */ +#ifdef DEBUG + fprintf(stderr, "%s: Name=%s major=%d minor=%d\n", + __FUNCTION__, item_name, sdc->major, sdc->minor); +#endif + continue; } } pos = k * 9; @@ -2253,7 +2202,7 @@ __print_funct_t svg_print_disk_stats(struct activity *a, int curr, int action, s } /* Mark devices not seen here as now unregistered */ - for (k = 0; k < svg_p->nr_max; k++) { + for (k = 0; k < a->item_list_sz; k++) { unregistered = outsize + k * 9 + 8; if (*unregistered != FALSE) { *unregistered = TRUE; @@ -2264,7 +2213,7 @@ __print_funct_t svg_print_disk_stats(struct activity *a, int curr, int action, s if (action & F_END) { int xid = 0; - for (i = 0; i < svg_p->nr_max; i++) { + for (i = 0; i < a->item_list_sz; i++) { /* Check if there is something to display */ pos = i * 9; if (!**(out + pos)) @@ -2333,7 +2282,7 @@ __print_funct_t svg_print_net_dev_stats(struct activity *a, int curr, int action * outsize + 8 will contain a positive value (TRUE) if the interface * has either still not been registered, or has been unregistered. */ - out = allocate_graph_lines(9 * svg_p->nr_max, &outsize, &spmin, &spmax); + out = allocate_graph_lines(9 * a->item_list_sz, &outsize, &spmin, &spmax); } if (action & F_MAIN) { @@ -2343,7 +2292,7 @@ __print_funct_t svg_print_net_dev_stats(struct activity *a, int curr, int action * Mark previously registered interfaces as now * possibly unregistered for all graphs. */ - for (k = 0; k < svg_p->nr_max; k++) { + for (k = 0; k < a->item_list_sz; k++) { unregistered = outsize + k * 9 + 8; if (*unregistered == FALSE) { *unregistered = MAYBE; @@ -2354,32 +2303,34 @@ __print_funct_t svg_print_net_dev_stats(struct activity *a, int curr, int action for (i = 0; i < a->nr[curr]; i++) { sndc = (struct stats_net_dev *) ((char *) a->buf[curr] + i * a->msize); - if (dlst_iface_idx) { + if (a->item_list != NULL) { /* A list of devices has been entered on the command line */ - if (!search_sa_dlist(st_iface_list, dlst_iface_idx, sndc->interface)) + if (!search_list_item(a->item_list, sndc->interface)) /* Device not found */ continue; } /* Look for corresponding graph */ - for (k = 0; k < svg_p->nr_max; k++) { + for (k = 0; k < a->item_list_sz; k++) { item_name = *(out + k * 9 + 8); if (!strcmp(sndc->interface, item_name)) /* Graph found! */ break; } - if (k == svg_p->nr_max) { + if (k == a->item_list_sz) { /* Graph not found: Look for first free entry */ - for (k = 0; k < svg_p->nr_max; k++) { + for (k = 0; k < a->item_list_sz; k++) { item_name = *(out + k * 9 + 8); if (!strcmp(item_name, "")) break; } - if (k == svg_p->nr_max) { - /* No free graph entry: Extend all buffers */ - reallocate_all_graph_lines(9 * svg_p->nr_max, - &out, &outsize, &spmin, &spmax); - svg_p->nr_max *= 2; + if (k == a->item_list_sz) { + /* No free graph entry: Ignore it (should never happen) */ +#ifdef DEBUG + fprintf(stderr, "%s: Name=%s\n", + __FUNCTION__, sndc->interface); +#endif + continue; } } pos = k * 9; @@ -2460,7 +2411,7 @@ __print_funct_t svg_print_net_dev_stats(struct activity *a, int curr, int action } /* Mark interfaces not seen here as now unregistered */ - for (k = 0; k < svg_p->nr_max; k++) { + for (k = 0; k < a->item_list_sz; k++) { unregistered = outsize + k * 9 + 8; if (*unregistered != FALSE) { *unregistered = TRUE; @@ -2471,7 +2422,7 @@ __print_funct_t svg_print_net_dev_stats(struct activity *a, int curr, int action if (action & F_END) { int xid = 0; - for (i = 0; i < svg_p->nr_max; i++) { + for (i = 0; i < a->item_list_sz; i++) { /* * Check if there is something to display. * Don't test sndc->interface because maybe the network @@ -2546,7 +2497,7 @@ __print_funct_t svg_print_net_edev_stats(struct activity *a, int curr, int actio * outsize + 9 will contain a positive value (TRUE) if the interface * has either still not been registered, or has been unregistered. */ - out = allocate_graph_lines(10 * svg_p->nr_max, &outsize, &spmin, &spmax); + out = allocate_graph_lines(10 * a->item_list_sz, &outsize, &spmin, &spmax); } if (action & F_MAIN) { @@ -2556,7 +2507,7 @@ __print_funct_t svg_print_net_edev_stats(struct activity *a, int curr, int actio * Mark previously registered interfaces as now * possibly unregistered for all graphs. */ - for (k = 0; k < svg_p->nr_max; k++) { + for (k = 0; k < a->item_list_sz; k++) { unregistered = outsize + k * 10 + 9; if (*unregistered == FALSE) { *unregistered = MAYBE; @@ -2570,32 +2521,34 @@ __print_funct_t svg_print_net_edev_stats(struct activity *a, int curr, int actio /* Empty structure: This is the end of the list */ break; - if (dlst_iface_idx) { + if (a->item_list != NULL) { /* A list of devices has been entered on the command line */ - if (!search_sa_dlist(st_iface_list, dlst_iface_idx, snedc->interface)) + if (!search_list_item(a->item_list, snedc->interface)) /* Device not found */ continue; } /* Look for corresponding graph */ - for (k = 0; k < svg_p->nr_max; k++) { + for (k = 0; k < a->item_list_sz; k++) { item_name = *(out + k * 10 + 9); if (!strcmp(snedc->interface, item_name)) /* Graph found! */ break; } - if (k == svg_p->nr_max) { + if (k == a->item_list_sz) { /* Graph not found: Look for first free entry */ - for (k = 0; k < svg_p->nr_max; k++) { + for (k = 0; k < a->item_list_sz; k++) { item_name = *(out + k * 10 + 9); if (!strcmp(item_name, "")) break; } - if (k == svg_p->nr_max) { - /* No free graph entry: Extend all buffers */ - reallocate_all_graph_lines(10 * svg_p->nr_max, - &out, &outsize, &spmin, &spmax); - svg_p->nr_max *= 2; + if (k == a->item_list_sz) { + /* No free graph entry: Ignore it (should never happen) */ +#ifdef DEBUG + fprintf(stderr, "%s: Name=%s\n", + __FUNCTION__, snedc->interface); +#endif + continue; } } @@ -2671,7 +2624,7 @@ __print_funct_t svg_print_net_edev_stats(struct activity *a, int curr, int actio } /* Mark interfaces not seen here as now unregistered */ - for (k = 0; k < svg_p->nr_max; k++) { + for (k = 0; k < a->item_list_sz; k++) { unregistered = outsize + k * 10 + 9; if (*unregistered != FALSE) { *unregistered = TRUE; @@ -2682,7 +2635,7 @@ __print_funct_t svg_print_net_edev_stats(struct activity *a, int curr, int actio if (action & F_END) { int xid = 0; - for (i = 0; i < svg_p->nr_max; i++) { + for (i = 0; i < a->item_list_sz; i++) { /* * Check if there is something to display. * Don't test snedc->interface because maybe the network @@ -4216,7 +4169,7 @@ __print_funct_t svg_print_pwr_cpufreq_stats(struct activity *a, int curr, int ac * Allocate arrays that will contain the graphs data * and the min/max values. */ - out = allocate_graph_lines(svg_p->nr_max, &outsize, &spmin, &spmax); + out = allocate_graph_lines(a->item_list_sz, &outsize, &spmin, &spmax); } if (action & F_MAIN) { @@ -4248,7 +4201,7 @@ __print_funct_t svg_print_pwr_cpufreq_stats(struct activity *a, int curr, int ac if (action & F_END) { int xid = 0; - for (i = 0; (i < svg_p->nr_max) && (i < a->bitmap->b_size + 1); i++) { + for (i = 0; (i < a->item_list_sz) && (i < a->bitmap->b_size + 1); i++) { /* Should current CPU (including CPU "all") be displayed? */ if (!(a->bitmap->b_array[i >> 3] & (1 << (i & 0x07)))) @@ -4319,7 +4272,7 @@ __print_funct_t svg_print_pwr_fan_stats(struct activity *a, int curr, int action * Allocate arrays that will contain the graphs data * and the min/max values. */ - out = allocate_graph_lines(svg_p->nr_max, &outsize, &spmin, &spmax); + out = allocate_graph_lines(a->item_list_sz, &outsize, &spmin, &spmax); } if (action & F_MAIN) { @@ -4341,7 +4294,7 @@ __print_funct_t svg_print_pwr_fan_stats(struct activity *a, int curr, int action if (action & F_END) { int xid = 0; - for (i = 0; i < svg_p->nr_max; i++) { + for (i = 0; i < a->item_list_sz; i++) { spc = (struct stats_pwr_fan *) ((char *) a->buf[curr] + i * a->msize); @@ -4399,7 +4352,7 @@ __print_funct_t svg_print_pwr_temp_stats(struct activity *a, int curr, int actio * Allocate arrays that will contain the graphs data * and the min/max values. */ - out = allocate_graph_lines(2 * svg_p->nr_max, &outsize, &spmin, &spmax); + out = allocate_graph_lines(2 * a->item_list_sz, &outsize, &spmin, &spmax); } if (action & F_MAIN) { @@ -4439,7 +4392,7 @@ __print_funct_t svg_print_pwr_temp_stats(struct activity *a, int curr, int actio if (action & F_END) { int xid = 0; - for (i = 0; i < svg_p->nr_max; i++) { + for (i = 0; i < a->item_list_sz; i++) { spc = (struct stats_pwr_temp *) ((char *) a->buf[curr] + i * a->msize); @@ -4497,7 +4450,7 @@ __print_funct_t svg_print_pwr_in_stats(struct activity *a, int curr, int action, * Allocate arrays that will contain the graphs data * and the min/max values. */ - out = allocate_graph_lines(2 * svg_p->nr_max, &outsize, &spmin, &spmax); + out = allocate_graph_lines(2 * a->item_list_sz, &outsize, &spmin, &spmax); } if (action & F_MAIN) { @@ -4537,7 +4490,7 @@ __print_funct_t svg_print_pwr_in_stats(struct activity *a, int curr, int action, if (action & F_END) { int xid = 0; - for (i = 0; i < svg_p->nr_max; i++) { + for (i = 0; i < a->item_list_sz; i++) { spc = (struct stats_pwr_in *) ((char *) a->buf[curr] + i * a->msize); @@ -4686,7 +4639,7 @@ __print_funct_t svg_print_filesystem_stats(struct activity *a, int curr, int act * out + 7 will contain the filesystem name, * out + 8 will contain the mount point. */ - out = allocate_graph_lines(9 * svg_p->nr_max, &outsize, &spmin, &spmax); + out = allocate_graph_lines(9 * a->item_list_sz, &outsize, &spmin, &spmax); } if (action & F_MAIN) { @@ -4694,34 +4647,36 @@ __print_funct_t svg_print_filesystem_stats(struct activity *a, int curr, int act for (i = 0; i < a->nr[curr]; i++) { sfc = (struct stats_filesystem *) ((char *) a->buf[curr] + i * a->msize); - if (dlst_fs_idx) { + if (a->item_list != NULL) { /* A list of devices has been entered on the command line */ - if (!search_sa_dlist(st_fs_list, dlst_fs_idx, - DISPLAY_MOUNT(a->opt_flags) ? sfc->mountp : sfc->fs_name)) + if (!search_list_item(a->item_list, + DISPLAY_MOUNT(a->opt_flags) ? sfc->mountp : sfc->fs_name)) /* Device not found */ continue; } /* Look for corresponding graph */ - for (k = 0; k < svg_p->nr_max; k++) { + for (k = 0; k < a->item_list_sz; k++) { item_name = *(out + k * 9 + 7); if (!strcmp(sfc->fs_name, item_name)) /* Graph found! */ break; } - if (k == svg_p->nr_max) { + if (k == a->item_list_sz) { /* Graph not found: Look for first free entry */ - for (k = 0; k < svg_p->nr_max; k++) { + for (k = 0; k < a->item_list_sz; k++) { item_name = *(out + k * 9 + 7); if (!strcmp(item_name, "")) break; } - if (k == svg_p->nr_max) { - /* No free graph entry: Extend all buffers */ - reallocate_all_graph_lines(9 * svg_p->nr_max, - &out, &outsize, &spmin, &spmax); - svg_p->nr_max *= 2; + if (k == a->item_list_sz) { + /* No free graph entry: Ignore it (should never happen) */ +#ifdef DEBUG + fprintf(stderr, "%s: Name=%s\n", + __FUNCTION__, sfc->fs_name); +#endif + continue; } } @@ -4848,7 +4803,7 @@ __print_funct_t svg_print_filesystem_stats(struct activity *a, int curr, int act if (action & F_END) { int xid = 0; - for (i = 0; i < svg_p->nr_max; i++) { + for (i = 0; i < a->item_list_sz; i++) { /* Check if there is something to display */ pos = i * 9; @@ -4923,7 +4878,7 @@ __print_funct_t svg_print_fchost_stats(struct activity *a, int curr, int action, * has either still not been registered, or has been unregistered * (outsize + 4). */ - out = allocate_graph_lines(5 * svg_p->nr_max, &outsize, &spmin, &spmax); + out = allocate_graph_lines(5 * a->item_list_sz, &outsize, &spmin, &spmax); } if (action & F_MAIN) { @@ -4932,7 +4887,7 @@ __print_funct_t svg_print_fchost_stats(struct activity *a, int curr, int action, * Mark previously registered interfaces as now * possibly unregistered for all graphs. */ - for (k = 0; k < svg_p->nr_max; k++) { + for (k = 0; k < a->item_list_sz; k++) { unregistered = outsize + k * 5 + 4; if (*unregistered == FALSE) { *unregistered = MAYBE; @@ -4948,24 +4903,26 @@ __print_funct_t svg_print_fchost_stats(struct activity *a, int curr, int action, sfcc = (struct stats_fchost *) ((char *) a->buf[curr] + i * a->msize); /* Look for corresponding graph */ - for (k = 0; k < svg_p->nr_max; k++) { + for (k = 0; k < a->item_list_sz; k++) { item_name = *(out + k * 5 + 4); if (!strcmp(sfcc->fchost_name, item_name)) /* Graph found! */ break; } - if (k == svg_p->nr_max) { + if (k == a->item_list_sz) { /* Graph not found: Look for first free entry */ - for (k = 0; k < svg_p->nr_max; k++) { + for (k = 0; k < a->item_list_sz; k++) { item_name = *(out + k * 5 + 4); if (!strcmp(item_name, "")) break; } - if (k == svg_p->nr_max) { - /* No free graph entry: Extend all buffers */ - reallocate_all_graph_lines(5 * svg_p->nr_max, - &out, &outsize, &spmin, &spmax); - svg_p->nr_max *= 2; + if (k == a->item_list_sz) { + /* No free graph entry: Ignore it (should never happen) */ +#ifdef DEBUG + fprintf(stderr, "%s: Name=%s\n", + __FUNCTION__, sfcc->fchost_name); +#endif + continue; } } @@ -5037,7 +4994,7 @@ __print_funct_t svg_print_fchost_stats(struct activity *a, int curr, int action, } /* Mark interfaces not seen here as now unregistered */ - for (k = 0; k < svg_p->nr_max; k++) { + for (k = 0; k < a->item_list_sz; k++) { unregistered = outsize + k * 5 + 4; if (*unregistered != FALSE) { *unregistered = TRUE; @@ -5046,7 +5003,7 @@ __print_funct_t svg_print_fchost_stats(struct activity *a, int curr, int action, } if (action & F_END) { - for (i = 0; i < svg_p->nr_max; i++) { + for (i = 0; i < a->item_list_sz; i++) { /* Check if there is something to display */ pos = i * 5; @@ -5104,7 +5061,7 @@ __print_funct_t svg_print_softnet_stats(struct activity *a, int curr, int action * Allocate arrays that will contain the graphs data * and the min/max values. */ - out = allocate_graph_lines(5 * svg_p->nr_max, &outsize, &spmin, &spmax); + out = allocate_graph_lines(5 * a->item_list_sz, &outsize, &spmin, &spmax); } if (action & F_MAIN) { @@ -5177,7 +5134,7 @@ __print_funct_t svg_print_softnet_stats(struct activity *a, int curr, int action } if (action & F_END) { - for (i = 0; (i < svg_p->nr_max) && (i < a->bitmap->b_size + 1); i++) { + for (i = 0; (i < a->item_list_sz) && (i < a->bitmap->b_size + 1); i++) { /* Should current CPU (including CPU "all") be displayed? */ if (!(a->bitmap->b_array[i >> 3] & (1 << (i & 0x07)))) diff --git a/xml_stats.c b/xml_stats.c index e7a1873..2198ba7 100644 --- a/xml_stats.c +++ b/xml_stats.c @@ -36,12 +36,6 @@ #endif extern unsigned int flags; -extern struct sa_dlist *st_iface_list; -extern struct sa_dlist *st_dev_list; -extern struct sa_dlist *st_fs_list; -extern int dlst_iface_idx; -extern int dlst_dev_idx; -extern int dlst_fs_idx; /* *************************************************************************** @@ -720,9 +714,9 @@ __print_funct_t xml_print_disk_stats(struct activity *a, int curr, int tab, /* Get device name */ dev_name = get_sa_devname(sdc->major, sdc->minor, flags); - if (dlst_dev_idx) { + if (a->item_list != NULL) { /* A list of devices has been entered on the command line */ - if (!search_sa_dlist(st_dev_list, dlst_dev_idx, dev_name)) + if (!search_list_item(a->item_list, dev_name)) /* Device not found */ continue; } @@ -793,9 +787,9 @@ __print_funct_t xml_print_net_dev_stats(struct activity *a, int curr, int tab, sndc = (struct stats_net_dev *) ((char *) a->buf[curr] + i * a->msize); - if (dlst_iface_idx) { + if (a->item_list != NULL) { /* A list of devices has been entered on the command line */ - if (!search_sa_dlist(st_iface_list, dlst_iface_idx, sndc->interface)) + if (!search_list_item(a->item_list, sndc->interface)) /* Device not found */ continue; } @@ -869,9 +863,9 @@ __print_funct_t xml_print_net_edev_stats(struct activity *a, int curr, int tab, snedc = (struct stats_net_edev *) ((char *) a->buf[curr] + i * a->msize); - if (dlst_iface_idx) { + if (a->item_list != NULL) { /* A list of devices has been entered on the command line */ - if (!search_sa_dlist(st_iface_list, dlst_iface_idx, snedc->interface)) + if (!search_list_item(a->item_list, snedc->interface)) /* Device not found */ continue; } @@ -2083,10 +2077,10 @@ __print_funct_t xml_print_filesystem_stats(struct activity *a, int curr, int tab sfc = (struct stats_filesystem *) ((char *) a->buf[curr] + i * a->msize); - if (dlst_fs_idx) { + if (a->item_list != NULL) { /* A list of devices has been entered on the command line */ - if (!search_sa_dlist(st_fs_list, dlst_fs_idx, - DISPLAY_MOUNT(a->opt_flags) ? sfc->mountp : sfc->fs_name)) + if (!search_list_item(a->item_list, + DISPLAY_MOUNT(a->opt_flags) ? sfc->mountp : sfc->fs_name)) /* Device not found */ continue; }