]> granicus.if.org Git - sysstat/blobdiff - count.c
A_IRQ: sar: Always display a header line for each sample
[sysstat] / count.c
diff --git a/count.c b/count.c
index b57caaca898d6c46a225c4973b4df5d3c4d633a8..0c49be0eb0cff36e62f83de78f71663f1c7eb189 100644 (file)
--- a/count.c
+++ b/count.c
@@ -1,6 +1,6 @@
 /*
  * count.c: Count items for which statistics will be collected.
- * (C) 1999-2018 by Sebastien GODARD (sysstat <at> orange.fr)
+ * (C) 1999-2021 by Sebastien GODARD (sysstat <at> orange.fr)
  *
  ***************************************************************************
  * This program is free software; you can redistribute it and/or modify it *
@@ -73,8 +73,8 @@ int get_sys_cpu_nr(int highest)
        while ((drd = readdir(dir)) != NULL) {
 
                if (!strncmp(drd->d_name, "cpu", 3) && isdigit(drd->d_name[3])) {
-                       snprintf(line, MAX_PF_NAME, "%s/%s", SYSFS_DEVCPU, drd->d_name);
-                       line[MAX_PF_NAME - 1] = '\0';
+                       snprintf(line, sizeof(line), "%s/%s", SYSFS_DEVCPU, drd->d_name);
+                       line[sizeof(line) - 1] = '\0';
                        if (stat(line, &buf) < 0)
                                continue;
                        if (S_ISDIR(buf.st_mode)) {
@@ -154,6 +154,9 @@ int get_proc_cpu_nr(void)
  *    one have been disabled, we get the total number of proc since we use
  *    /sys to count them).
  * 2: two proc...
+ *
+ * USED BY:
+ * sadc, cifsiostat, iostat, mpstat, pidstat, tapestat
  ***************************************************************************
  */
 __nr_t get_cpu_nr(unsigned int max_nr_cpus, int highest)
@@ -186,6 +189,9 @@ __nr_t get_cpu_nr(unsigned int max_nr_cpus, int highest)
  *
  * RETURNS:
  * Number of interrupts per processor.
+ *
+ * USED BY:
+ * sadc, mpstat
  ***************************************************************************
  */
 __nr_t get_irqcpu_nr(char *file, int max_nr_irqcpu, int cpu_nr)
@@ -215,6 +221,9 @@ __nr_t get_irqcpu_nr(char *file, int max_nr_irqcpu, int cpu_nr)
        return irq;
 }
 
+#ifdef SOURCE_SADC
+/*---------------- BEGIN: FUNCTIONS USED BY SADC ONLY ---------------------*/
+
 /*
  ***************************************************************************
  * Find number of devices and partitions available in /proc/diskstats.
@@ -250,7 +259,7 @@ __nr_t get_diskstats_dev_nr(int count_part, int only_used_dev)
                if (!count_part) {
                        i = sscanf(line, "%*d %*d %s %lu %*u %*u %*u %lu",
                                   dev_name, &rd_ios, &wr_ios);
-                       if ((i == 2) || !is_device(dev_name, ACCEPT_VIRTUAL_DEVICES))
+                       if ((i == 2) || !is_device(SLASH_SYS, dev_name, ACCEPT_VIRTUAL_DEVICES))
                                /* It was a partition and not a device */
                                continue;
                        if (only_used_dev && !rd_ios && !wr_ios)
@@ -265,43 +274,6 @@ __nr_t get_diskstats_dev_nr(int count_part, int only_used_dev)
        return dev;
 }
 
-#ifdef SOURCE_SADC
-/*---------------- BEGIN: FUNCTIONS USED BY SADC ONLY ---------------------*/
-
-/*
- ***************************************************************************
- * Count number of interrupts that are in /proc/stat file.
- *
- * RETURNS:
- * Number of interrupts, including total number of interrupts.
- ***************************************************************************
- */
-__nr_t get_irq_nr(void)
-{
-       FILE *fp;
-       char line[8192];
-       __nr_t in = 0;
-       int pos = 4;
-
-       if ((fp = fopen(STAT, "r")) == NULL)
-               return 0;
-
-       while (fgets(line, sizeof(line), fp) != NULL) {
-
-               if (!strncmp(line, "intr ", 5)) {
-
-                       while (pos < strlen(line)) {
-                               in++;
-                               pos += strcspn(line + pos + 1, " ") + 1;
-                       }
-               }
-       }
-
-       fclose(fp);
-
-       return in;
-}
-
 /*
  ***************************************************************************
  * Find number of serial lines that support tx/rx accounting
@@ -463,8 +435,8 @@ __nr_t get_usb_nr(void)
 __nr_t get_filesystem_nr(void)
 {
        FILE *fp;
-       char line[512], fs_name[MAX_FS_LEN], mountp[256];
-       char *pos = 0;
+       char line[512], fs_name[MAX_FS_LEN], mountp[256], type[128];
+       char *pos = 0, *pos2 = 0;
        __nr_t fs = 0;
        int skip = 0, skip_next = 0;
        struct statvfs buf;
@@ -491,6 +463,19 @@ __nr_t get_filesystem_nr(void)
                        if (pos == NULL)
                                continue;
 
+                       /*
+                        * Find second field separator position,
+                        * read filesystem type,
+                        * if filesystem type is autofs, skip it
+                       */
+                       pos2 = strchr(pos + 1, ' ');
+                       if (pos2 == NULL)
+                               continue;
+
+                       sscanf(pos2 + 1, "%127s", type);
+                       if(strcmp(type, "autofs") == 0)
+                               continue;
+
                        /* Read filesystem name and mount point */
                        sscanf(line, "%127s", fs_name);
                        sscanf(pos + 1, "%255s", mountp);
@@ -499,7 +484,7 @@ __nr_t get_filesystem_nr(void)
                        oct2chr(mountp);
 
                        /* Check that total size is not zero */
-                       if (statvfs(mountp, &buf) < 0)
+                       if (__statvfs(mountp, &buf) < 0)
                                continue;
 
                        if (buf.f_blocks) {