]> granicus.if.org Git - sysstat/commitdiff
Added filesystems statistics to sar (part 1): Basic definitions and structures
authorseb <sysstat@orange.fr.fake>
Mon, 29 Apr 2013 20:04:43 +0000 (22:04 +0200)
committerseb <sysstat@orange.fr.fake>
Mon, 29 Apr 2013 20:04:43 +0000 (22:04 +0200)
A new option (-F) has been added to sar. This option tells sar to display
filesystems statistics.
This first patch adds the corresponding structures, constants and the new
functions prototypes.
sar's help and usage messages have also been updated.

14 files changed:
activity.c
json_stats.c
json_stats.h
pr_stats.c
pr_stats.h
rd_stats.h
rndr_stats.c
rndr_stats.h
sa.h
sa_common.c
sa_wrap.c
sar.c
xml_stats.c
xml_stats.h

index 103df7aefd2b35b128e2823cc29153dd1b9c3062..b1aba3766f0a9db016d57b0100832cfc897f51f2 100644 (file)
@@ -1195,6 +1195,37 @@ struct activity pwr_usb_act = {
        .bitmap         = NULL
 };
 
+/* Filesystem usage activity */
+struct activity filesystem_act = {
+       .id             = A_FILESYSTEM,
+       .options        = AO_NULL,
+       .magic          = ACTIVITY_MAGIC_BASE,
+       .group          = G_DISK,
+#ifdef SOURCE_SADC
+       .f_count        = wrap_get_filesystem_nr,
+       .f_count2       = NULL,
+       .f_read         = wrap_read_filesystem,
+#endif
+#ifdef SOURCE_SAR
+       .f_print        = print_filesystem_stats,
+       .f_print_avg    = print_avg_filesystem_stats,
+#endif
+#ifdef SOURCE_SADF
+       .f_render       = render_filesystem_stats,
+       .f_xml_print    = xml_print_filesystem_stats,
+       .f_json_print   = json_print_filesystem_stats,
+       .hdr_line       = "Mbfsfree;Mbfsused;%fsused;%ufsused;Ifree;Iused;%Iused;FILESYSTEM",
+       .name           = "A_FILESYSTEM",
+#endif
+       .nr             = -1,
+       .nr2            = 1,
+       .fsize          = STATS_FILESYSTEM_SIZE,
+       .msize          = STATS_FILESYSTEM_SIZE,
+       .opt_flags      = 0,
+       .buf            = {NULL, NULL, NULL},
+       .bitmap         = NULL
+};
+
 
 /*
  * Array of activities.
@@ -1239,6 +1270,7 @@ struct activity *act[NR_ACT] = {
        &pwr_temp_act,
        &pwr_in_act,
        &pwr_wghfreq_act,
-       &pwr_usb_act            /* AO_CLOSE_MARKUP */
+       &pwr_usb_act,           /* AO_CLOSE_MARKUP */
        /* </power-management> */
+       &filesystem_act
 };
index a75b4221222a69f9753d8cd42a0717eacdb93f73..10d88e9c25d9310376a7e4e39726e9a2023d6aa0 100644 (file)
@@ -2085,3 +2085,20 @@ close_json_markup:
                json_markup_power_management(tab, CLOSE_JSON_MARKUP);
        }
 }
+
+/*
+ ***************************************************************************
+ * Display filesystems statistics in JSON.
+ *
+ * IN:
+ * @a          Activity structure with statistics.
+ * @curr       Index in array for current sample statistics.
+ * @tab                Indentation in output.
+ * @itv                Interval of time in jiffies.
+ ***************************************************************************
+ */
+__print_funct_t json_print_filesystem_stats(struct activity *a, int curr, int tab,
+                                           unsigned long long itv)
+{
+       /* FIXME */
+}
index 9f8044535e3adc9a4d1625d029e4ccffa60a0922..9244931942ea0ac8c53960f758ed92a5ba8492d9 100644 (file)
@@ -87,5 +87,7 @@ extern __print_funct_t json_print_pwr_wghfreq_stats
        (struct activity *, int, int, unsigned long long);
 extern __print_funct_t json_print_pwr_usb_stats
        (struct activity *, int, int, unsigned long long);
+extern __print_funct_t json_print_filesystem_stats
+       (struct activity *, int, int, unsigned long long);
 
 #endif /* _XML_STATS_H */
index ab1b8417f97173a99c95f4c8f9e213c5a07d9977..332b10eccbbc8c6644b162f8b9870c5a7cc7f72a 100644 (file)
@@ -2437,3 +2437,56 @@ __print_funct_t print_avg_pwr_usb_stats(struct activity *a, int prev, int curr,
 {
        stub_print_pwr_usb_stats(a, 2, TRUE);
 }
+
+/*
+ ***************************************************************************
+ * Display filesystems statistics. This function is used to
+ * display instantaneous and average statistics.
+ *
+ * IN:
+ * @a          Activity structure with statistics.
+ * @prev       Index in array where stats used as reference are.
+ * @curr       Index in array for current sample statistics.
+ * @itv                Interval of time in jiffies.
+ * @dispavg    TRUE if displaying average statistics.
+ ***************************************************************************
+ */
+__print_funct_t stub_print_filesystem_stats(struct activity *a, int prev, int curr,
+                                           unsigned long long itv, int dispavg)
+{
+       /* FIXME */
+}
+
+/*
+ ***************************************************************************
+ * Display filesystems statistics.
+ *
+ * IN:
+ * @a          Activity structure with statistics.
+ * @prev       Index in array where stats used as reference are.
+ * @curr       Index in array for current sample statistics.
+ * @itv                Interval of time in jiffies.
+ ***************************************************************************
+ */
+__print_funct_t print_filesystem_stats(struct activity *a, int prev, int curr,
+                                      unsigned long long itv)
+{
+       stub_print_filesystem_stats(a, prev, curr, itv, FALSE);
+}
+
+/*
+ ***************************************************************************
+ * Display average filesystems statistics.
+ *
+ * IN:
+ * @a          Activity structure with statistics.
+ * @prev       Index in array where stats used as reference are.
+ * @curr       Index in array for current sample statistics.
+ * @itv                Interval of time in jiffies.
+ ***************************************************************************
+ */
+__print_funct_t print_avg_filesystem_stats(struct activity *a, int prev, int curr,
+                                          unsigned long long itv)
+{
+       stub_print_filesystem_stats(a, prev, curr, itv, TRUE);
+}
index 0f54aabd32d0fd0316721da466b5a595f1e19dc3..52007f89264bd7205510b2daa3ddcbe000f3da85 100644 (file)
@@ -88,6 +88,8 @@ extern __print_funct_t print_pwr_wghfreq_stats
        (struct activity *, int, int, unsigned long long);
 extern __print_funct_t print_pwr_usb_stats
        (struct activity *, int, int, unsigned long long);
+extern __print_funct_t print_filesystem_stats
+       (struct activity *, int, int, unsigned long long);
 
 /* Functions used to display average statistics */
 extern __print_funct_t print_avg_memory_stats
@@ -112,5 +114,7 @@ extern __print_funct_t print_avg_huge_stats
        (struct activity *, int, int, unsigned long long);
 extern __print_funct_t print_avg_pwr_usb_stats
        (struct activity *, int, int, unsigned long long);
+extern __print_funct_t print_avg_filesystem_stats
+       (struct activity *, int, int, unsigned long long);
 
 #endif /* _PR_STATS_H */
index 967f5849c936aef6f0a78c190368b4b849fdda4b..f941426ea95ebd198578fccdc720b923f414a6c6 100644 (file)
@@ -56,6 +56,7 @@
 #define NET_SNMP       "/proc/net/snmp"
 #define NET_SNMP6      "/proc/net/snmp6"
 #define CPUINFO                "/proc/cpuinfo"
+#define MTAB           "/etc/mtab"
 
 
 /*
@@ -520,6 +521,17 @@ struct stats_pwr_usb {
 
 #define STATS_PWR_USB_SIZE     (sizeof(struct stats_pwr_usb))
 
+/* Structure for filesystems statistics */
+struct stats_filesystem {
+       unsigned long long f_blocks     __attribute__ ((aligned (16)));
+       unsigned long long f_bfree      __attribute__ ((aligned (16)));
+       unsigned long long f_bavail     __attribute__ ((aligned (16)));
+       unsigned long long f_files      __attribute__ ((aligned (16)));
+       unsigned long long f_ffree      __attribute__ ((aligned (16)));
+};
+
+#define STATS_FILESYSTEM_SIZE  (sizeof(struct stats_filesystem))
+
 /*
  ***************************************************************************
  * Prototypes for functions used to read system statistics
index 41951035b74d6f34536e284fabbc412a3ac90701..8349e9ab28bde402ac92e900fd022aad805ff8b1 100644 (file)
@@ -2792,3 +2792,21 @@ __print_funct_t render_pwr_usb_stats(struct activity *a, int isdb, char *pre,
                       suc->product);
        }
 }
+
+/*
+ ***************************************************************************
+ * Display filesystems statistics in selected format.
+ *
+ * IN:
+ * @a          Activity structure with statistics.
+ * @isdb       Flag, true if db printing, false if ppc printing.
+ * @pre                Prefix string for output entries
+ * @curr       Index in array for current sample statistics.
+ * @itv                Interval of time in jiffies.
+ ***************************************************************************
+ */
+__print_funct_t render_filesystem_stats(struct activity *a, int isdb, char *pre,
+                                       int curr, unsigned long long itv)
+{
+       /* FIXME */
+}
index dbced2520c5816d624c0e9da924016e9ee3a9752..ff6452a141c959466930337233419e353293c727 100644 (file)
@@ -117,5 +117,7 @@ extern __print_funct_t render_pwr_wghfreq_stats
        (struct activity *, int, char *, int, unsigned long long);
 extern __print_funct_t render_pwr_usb_stats
        (struct activity *, int, char *, int, unsigned long long);
+extern __print_funct_t render_filesystem_stats
+       (struct activity *, int, char *, int, unsigned long long);
 
 #endif /* _RNDR_STATS_H */
diff --git a/sa.h b/sa.h
index 4a5038de09abbd9038a3e98d97ba9505995f3089..1a9199541c0c8951aa26ed04404306e644885bd9 100644 (file)
--- a/sa.h
+++ b/sa.h
@@ -19,7 +19,7 @@
  */
 
 /* Number of activities */
-#define NR_ACT 36
+#define NR_ACT 37
 
 /* Activities */
 #define A_CPU          1
@@ -58,6 +58,7 @@
 #define A_HUGE         34
 #define A_PWR_WGHFREQ  35
 #define A_PWR_USB      36
+#define A_FILESYSTEM   37
 
 
 /* Macro used to flag an activity that should be collected */
 #define NR_DISK_PREALLOC       3
 #define NR_FREQ_PREALLOC       0
 #define NR_USB_PREALLOC                5
+#define NR_FILESYSTEM_PREALLOC 3
 
 #define UTSNAME_LEN            65
 #define TIMESTAMP_LEN          16
@@ -706,6 +708,8 @@ extern __nr_t
        wrap_get_freq_nr(struct activity *);
 extern __nr_t
        wrap_get_usb_nr(struct activity *);
+extern __nr_t
+       wrap_get_filesystem_nr(struct activity *);
        
 /* Functions used to read activities statistics */
 extern __read_funct_t
@@ -780,6 +784,8 @@ extern __read_funct_t
        wrap_read_time_in_state(struct activity *);
 extern __read_funct_t
        wrap_read_bus_usb_dev(struct activity *);
+extern __read_funct_t
+       wrap_read_filesystem(struct activity *);
 
 /* Other functions */
 extern void
index b7ef6ad9983d8941732493e010120962fefe8be1..3d30d51237c2fb57cfd3edb173fac7b86c613a57 100644 (file)
@@ -1282,6 +1282,10 @@ int parse_sar_opt(char *argv[], int *opt, struct activity *act[],
                        SELECT_ACTIVITY(A_DISK);
                        break;
 
+               case 'F':
+                       SELECT_ACTIVITY(A_FILESYSTEM);
+                       break;
+                       
                case 'H':
                        p = get_activity_position(act, A_HUGE);
                        act[p]->options   |= AO_SELECTED;
index 321b2279617560f51219d9f4b1e152d8a615493f..298f889ce32371892619bb07516033b45fcac47b 100644 (file)
--- a/sa_wrap.c
+++ b/sa_wrap.c
@@ -847,6 +847,28 @@ __read_funct_t wrap_read_bus_usb_dev(struct activity *a)
        return;
 }
 
+/*
+ ***************************************************************************
+ * Read filesystem statistics.
+ *
+ * IN:
+ * @a  Activity structure.
+ *
+ * OUT:
+ * @a  Activity structure with statistics.
+ ***************************************************************************
+ */
+__read_funct_t wrap_read_filesystem(struct activity *a)
+{
+       struct stats_filesystem *st_filesystem
+               = (struct stats_filesystem *) a->_buf0;
+
+       /* Read filesystems from /etc/mtab */
+       /* FIXME */
+
+       return;
+}
+
 /*
  ***************************************************************************
  * Count number of interrupts that are in /proc/stat file.
@@ -1049,3 +1071,24 @@ __nr_t wrap_get_usb_nr(struct activity *a)
        
        return 0;
 }
+
+/*
+ ***************************************************************************
+ * Get number of mounted filesystems from /etc/mtab. Don't take into account
+ * pseudo-filesystems.
+ *
+ * IN:
+ * @a  Activity structure.
+ *
+ * RETURNS:
+ * Number of filesystems + a pre-allocation constant.
+ ***************************************************************************
+ */
+__nr_t wrap_get_filesystem_nr(struct activity *a)
+{
+       __nr_t n = 0;
+
+       /* FIXME */
+
+       return 0;
+}
diff --git a/sar.c b/sar.c
index e8ad83e3a253be50fac49c42e11dd2aa730493fb..ede71db053ab30773b84429dff47887f401a889f 100644 (file)
--- a/sar.c
+++ b/sar.c
@@ -107,7 +107,7 @@ void usage(char *progname)
 {
        print_usage_title(stderr, progname);
        fprintf(stderr, _("Options are:\n"
-                         "[ -A ] [ -B ] [ -b ] [ -C ] [ -d ] [ -H ] [ -h ] [ -p ] [ -q ] [ -R ]\n"
+                         "[ -A ] [ -B ] [ -b ] [ -C ] [ -d ] [ -F ] [ -H ] [ -h ] [ -p ] [ -q ] [ -R ]\n"
                          "[ -r ] [ -S ] [ -t ] [ -u [ ALL ] ] [ -V ] [ -v ] [ -W ] [ -w ] [ -y ]\n"
                          "[ -I { <int> [,...] | SUM | ALL | XALL } ] [ -P { <cpu> [,...] | ALL } ]\n"
                          "[ -m { <keyword> [,...] | ALL } ] [ -n { <keyword> [,...] | ALL } ]\n"
@@ -132,6 +132,7 @@ void display_help(char *progname)
        printf(_("\t-b\tI/O and transfer rate statistics\n"));
        printf(_("\t-B\tPaging statistics\n"));
        printf(_("\t-d\tBlock device statistics\n"));
+       printf(_("\t-F\tFilesystems statistics\n"));
        printf(_("\t-H\tHugepages utilization statistics\n"));
        printf(_("\t-I { <int> | SUM | ALL | XALL }\n"
                 "\t\tInterrupts statistics\n"));
index 66a685000ee549481b2b45d67e7d86b1ee257d23..0a15f98556dd51071102c8738bb5ecf6922222fb 100644 (file)
@@ -1989,4 +1989,21 @@ close_xml_markup:
        if (CLOSE_MARKUP(a->options)) {
                xml_markup_power_management(tab, CLOSE_XML_MARKUP);
        }
-}
\ No newline at end of file
+}
+
+/*
+ ***************************************************************************
+ * Display filesystems statistics in XML.
+ *
+ * IN:
+ * @a          Activity structure with statistics.
+ * @curr       Index in array for current sample statistics.
+ * @tab                Indentation in XML output.
+ * @itv                Interval of time in jiffies.
+ ***************************************************************************
+ */
+__print_funct_t xml_print_filesystem_stats(struct activity *a, int curr, int tab,
+                                          unsigned long long itv)
+{
+       /* FIXME */
+}
index 30098608f6f70e421f3106e7b18b9447b4715b5b..6258703921165124781f9dc6408056ef1988ba67 100644 (file)
@@ -87,5 +87,7 @@ extern __print_funct_t xml_print_pwr_wghfreq_stats
        (struct activity *, int, int, unsigned long long);
 extern __print_funct_t xml_print_pwr_usb_stats
        (struct activity *, int, int, unsigned long long);
+extern __print_funct_t xml_print_filesystem_stats
+       (struct activity *, int, int, unsigned long long);
 
 #endif /* _XML_STATS_H */