Blame SOURCES/0001-Added-filesystems-statistics-to-sar-part-1-Basic-def.patch

72abff
From a0e0995fec1286374ffe260843fdb9b7b01f98fa Mon Sep 17 00:00:00 2001
72abff
From: seb <sysstat@orange.fr.fake>
72abff
Date: Mon, 29 Apr 2013 22:04:43 +0200
72abff
Subject: [PATCH] Added filesystems statistics to sar (part 1): Basic
72abff
 definitions and structures
72abff
72abff
A new option (-F) has been added to sar. This option tells sar to display
72abff
filesystems statistics.
72abff
This first patch adds the corresponding structures, constants and the new
72abff
functions prototypes.
72abff
sar's help and usage messages have also been updated.
72abff
72abff
(cherry picked from commit fe061c6377d8b4550b794f4bf7d6d0ca6d4de34b)
72abff
---
72abff
 activity.c   | 34 +++++++++++++++++++++++++++++++++-
72abff
 json_stats.c | 17 +++++++++++++++++
72abff
 json_stats.h |  2 ++
72abff
 pr_stats.c   | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
72abff
 pr_stats.h   |  4 ++++
72abff
 rd_stats.h   | 12 ++++++++++++
72abff
 rndr_stats.c | 18 ++++++++++++++++++
72abff
 rndr_stats.h |  2 ++
72abff
 sa.h         |  8 +++++++-
72abff
 sa_common.c  |  4 ++++
72abff
 sa_wrap.c    | 43 +++++++++++++++++++++++++++++++++++++++++++
72abff
 sar.c        |  3 ++-
72abff
 xml_stats.c  | 19 ++++++++++++++++++-
72abff
 xml_stats.h  |  2 ++
72abff
 14 files changed, 217 insertions(+), 4 deletions(-)
72abff
72abff
diff --git a/activity.c b/activity.c
72abff
index 103df7a..b1aba37 100644
72abff
--- a/activity.c
72abff
+++ b/activity.c
72abff
@@ -1195,6 +1195,37 @@ struct activity pwr_usb_act = {
72abff
 	.bitmap		= NULL
72abff
 };
72abff
 
72abff
+/* Filesystem usage activity */
72abff
+struct activity filesystem_act = {
72abff
+	.id		= A_FILESYSTEM,
72abff
+	.options	= AO_NULL,
72abff
+	.magic		= ACTIVITY_MAGIC_BASE,
72abff
+	.group		= G_DISK,
72abff
+#ifdef SOURCE_SADC
72abff
+	.f_count	= wrap_get_filesystem_nr,
72abff
+	.f_count2	= NULL,
72abff
+	.f_read		= wrap_read_filesystem,
72abff
+#endif
72abff
+#ifdef SOURCE_SAR
72abff
+	.f_print	= print_filesystem_stats,
72abff
+	.f_print_avg	= print_avg_filesystem_stats,
72abff
+#endif
72abff
+#ifdef SOURCE_SADF
72abff
+	.f_render	= render_filesystem_stats,
72abff
+	.f_xml_print	= xml_print_filesystem_stats,
72abff
+	.f_json_print	= json_print_filesystem_stats,
72abff
+	.hdr_line	= "Mbfsfree;Mbfsused;%fsused;%ufsused;Ifree;Iused;%Iused;FILESYSTEM",
72abff
+	.name		= "A_FILESYSTEM",
72abff
+#endif
72abff
+	.nr		= -1,
72abff
+	.nr2		= 1,
72abff
+	.fsize		= STATS_FILESYSTEM_SIZE,
72abff
+	.msize		= STATS_FILESYSTEM_SIZE,
72abff
+	.opt_flags	= 0,
72abff
+	.buf		= {NULL, NULL, NULL},
72abff
+	.bitmap		= NULL
72abff
+};
72abff
+
72abff
 
72abff
 /*
72abff
  * Array of activities.
72abff
@@ -1239,6 +1270,7 @@ struct activity *act[NR_ACT] = {
72abff
 	&pwr_temp_act,
72abff
 	&pwr_in_act,
72abff
 	&pwr_wghfreq_act,
72abff
-	&pwr_usb_act		/* AO_CLOSE_MARKUP */
72abff
+	&pwr_usb_act,		/* AO_CLOSE_MARKUP */
72abff
 	/* </power-management> */
72abff
+	&filesystem_act
72abff
 };
72abff
diff --git a/json_stats.c b/json_stats.c
72abff
index a75b422..10d88e9 100644
72abff
--- a/json_stats.c
72abff
+++ b/json_stats.c
72abff
@@ -2085,3 +2085,20 @@ close_json_markup:
72abff
 		json_markup_power_management(tab, CLOSE_JSON_MARKUP);
72abff
 	}
72abff
 }
72abff
+
72abff
+/*
72abff
+ ***************************************************************************
72abff
+ * Display filesystems statistics in JSON.
72abff
+ *
72abff
+ * IN:
72abff
+ * @a		Activity structure with statistics.
72abff
+ * @curr	Index in array for current sample statistics.
72abff
+ * @tab		Indentation in output.
72abff
+ * @itv		Interval of time in jiffies.
72abff
+ ***************************************************************************
72abff
+ */
72abff
+__print_funct_t json_print_filesystem_stats(struct activity *a, int curr, int tab,
72abff
+					    unsigned long long itv)
72abff
+{
72abff
+	/* FIXME */
72abff
+}
72abff
diff --git a/json_stats.h b/json_stats.h
72abff
index 9f80445..9244931 100644
72abff
--- a/json_stats.h
72abff
+++ b/json_stats.h
72abff
@@ -87,5 +87,7 @@ extern __print_funct_t json_print_pwr_wghfreq_stats
72abff
 	(struct activity *, int, int, unsigned long long);
72abff
 extern __print_funct_t json_print_pwr_usb_stats
72abff
 	(struct activity *, int, int, unsigned long long);
72abff
+extern __print_funct_t json_print_filesystem_stats
72abff
+	(struct activity *, int, int, unsigned long long);
72abff
 
72abff
 #endif /* _XML_STATS_H */
72abff
diff --git a/pr_stats.c b/pr_stats.c
72abff
index ab1b841..332b10e 100644
72abff
--- a/pr_stats.c
72abff
+++ b/pr_stats.c
72abff
@@ -2437,3 +2437,56 @@ __print_funct_t print_avg_pwr_usb_stats(struct activity *a, int prev, int curr,
72abff
 {
72abff
 	stub_print_pwr_usb_stats(a, 2, TRUE);
72abff
 }
72abff
+
72abff
+/*
72abff
+ ***************************************************************************
72abff
+ * Display filesystems statistics. This function is used to
72abff
+ * display instantaneous and average statistics.
72abff
+ *
72abff
+ * IN:
72abff
+ * @a		Activity structure with statistics.
72abff
+ * @prev	Index in array where stats used as reference are.
72abff
+ * @curr	Index in array for current sample statistics.
72abff
+ * @itv		Interval of time in jiffies.
72abff
+ * @dispavg	TRUE if displaying average statistics.
72abff
+ ***************************************************************************
72abff
+ */
72abff
+__print_funct_t stub_print_filesystem_stats(struct activity *a, int prev, int curr,
72abff
+					    unsigned long long itv, int dispavg)
72abff
+{
72abff
+	/* FIXME */
72abff
+}
72abff
+
72abff
+/*
72abff
+ ***************************************************************************
72abff
+ * Display filesystems statistics.
72abff
+ *
72abff
+ * IN:
72abff
+ * @a		Activity structure with statistics.
72abff
+ * @prev	Index in array where stats used as reference are.
72abff
+ * @curr	Index in array for current sample statistics.
72abff
+ * @itv		Interval of time in jiffies.
72abff
+ ***************************************************************************
72abff
+ */
72abff
+__print_funct_t print_filesystem_stats(struct activity *a, int prev, int curr,
72abff
+				       unsigned long long itv)
72abff
+{
72abff
+	stub_print_filesystem_stats(a, prev, curr, itv, FALSE);
72abff
+}
72abff
+
72abff
+/*
72abff
+ ***************************************************************************
72abff
+ * Display average filesystems statistics.
72abff
+ *
72abff
+ * IN:
72abff
+ * @a		Activity structure with statistics.
72abff
+ * @prev	Index in array where stats used as reference are.
72abff
+ * @curr	Index in array for current sample statistics.
72abff
+ * @itv		Interval of time in jiffies.
72abff
+ ***************************************************************************
72abff
+ */
72abff
+__print_funct_t print_avg_filesystem_stats(struct activity *a, int prev, int curr,
72abff
+					   unsigned long long itv)
72abff
+{
72abff
+	stub_print_filesystem_stats(a, prev, curr, itv, TRUE);
72abff
+}
72abff
diff --git a/pr_stats.h b/pr_stats.h
72abff
index 0f54aab..52007f8 100644
72abff
--- a/pr_stats.h
72abff
+++ b/pr_stats.h
72abff
@@ -88,6 +88,8 @@ extern __print_funct_t print_pwr_wghfreq_stats
72abff
 	(struct activity *, int, int, unsigned long long);
72abff
 extern __print_funct_t print_pwr_usb_stats
72abff
 	(struct activity *, int, int, unsigned long long);
72abff
+extern __print_funct_t print_filesystem_stats
72abff
+	(struct activity *, int, int, unsigned long long);
72abff
 
72abff
 /* Functions used to display average statistics */
72abff
 extern __print_funct_t print_avg_memory_stats
72abff
@@ -112,5 +114,7 @@ extern __print_funct_t print_avg_huge_stats
72abff
 	(struct activity *, int, int, unsigned long long);
72abff
 extern __print_funct_t print_avg_pwr_usb_stats
72abff
 	(struct activity *, int, int, unsigned long long);
72abff
+extern __print_funct_t print_avg_filesystem_stats
72abff
+	(struct activity *, int, int, unsigned long long);
72abff
 
72abff
 #endif /* _PR_STATS_H */
72abff
diff --git a/rd_stats.h b/rd_stats.h
72abff
index 967f584..f941426 100644
72abff
--- a/rd_stats.h
72abff
+++ b/rd_stats.h
72abff
@@ -56,6 +56,7 @@
72abff
 #define NET_SNMP	"/proc/net/snmp"
72abff
 #define NET_SNMP6	"/proc/net/snmp6"
72abff
 #define CPUINFO		"/proc/cpuinfo"
72abff
+#define MTAB		"/etc/mtab"
72abff
 
72abff
 
72abff
 /*
72abff
@@ -520,6 +521,17 @@ struct stats_pwr_usb {
72abff
 
72abff
 #define STATS_PWR_USB_SIZE	(sizeof(struct stats_pwr_usb))
72abff
 
72abff
+/* Structure for filesystems statistics */
72abff
+struct stats_filesystem {
72abff
+	unsigned long long f_blocks	__attribute__ ((aligned (16)));
72abff
+	unsigned long long f_bfree	__attribute__ ((aligned (16)));
72abff
+	unsigned long long f_bavail	__attribute__ ((aligned (16)));
72abff
+	unsigned long long f_files	__attribute__ ((aligned (16)));
72abff
+	unsigned long long f_ffree	__attribute__ ((aligned (16)));
72abff
+};
72abff
+
72abff
+#define STATS_FILESYSTEM_SIZE	(sizeof(struct stats_filesystem))
72abff
+
72abff
 /*
72abff
  ***************************************************************************
72abff
  * Prototypes for functions used to read system statistics
72abff
diff --git a/rndr_stats.c b/rndr_stats.c
72abff
index 4195103..8349e9a 100644
72abff
--- a/rndr_stats.c
72abff
+++ b/rndr_stats.c
72abff
@@ -2792,3 +2792,21 @@ __print_funct_t render_pwr_usb_stats(struct activity *a, int isdb, char *pre,
72abff
 		       suc->product);
72abff
 	}
72abff
 }
72abff
+
72abff
+/*
72abff
+ ***************************************************************************
72abff
+ * Display filesystems statistics in selected format.
72abff
+ *
72abff
+ * IN:
72abff
+ * @a		Activity structure with statistics.
72abff
+ * @isdb	Flag, true if db printing, false if ppc printing.
72abff
+ * @pre		Prefix string for output entries
72abff
+ * @curr	Index in array for current sample statistics.
72abff
+ * @itv		Interval of time in jiffies.
72abff
+ ***************************************************************************
72abff
+ */
72abff
+__print_funct_t render_filesystem_stats(struct activity *a, int isdb, char *pre,
72abff
+					int curr, unsigned long long itv)
72abff
+{
72abff
+	/* FIXME */
72abff
+}
72abff
diff --git a/rndr_stats.h b/rndr_stats.h
72abff
index dbced25..ff6452a 100644
72abff
--- a/rndr_stats.h
72abff
+++ b/rndr_stats.h
72abff
@@ -117,5 +117,7 @@ extern __print_funct_t render_pwr_wghfreq_stats
72abff
 	(struct activity *, int, char *, int, unsigned long long);
72abff
 extern __print_funct_t render_pwr_usb_stats
72abff
 	(struct activity *, int, char *, int, unsigned long long);
72abff
+extern __print_funct_t render_filesystem_stats
72abff
+	(struct activity *, int, char *, int, unsigned long long);
72abff
 
72abff
 #endif /* _RNDR_STATS_H */
72abff
diff --git a/sa.h b/sa.h
72abff
index c11dbe9..50349c8 100644
72abff
--- a/sa.h
72abff
+++ b/sa.h
72abff
@@ -19,7 +19,7 @@
72abff
  */
72abff
 
72abff
 /* Number of activities */
72abff
-#define NR_ACT	36
72abff
+#define NR_ACT	37
72abff
 
72abff
 /* Activities */
72abff
 #define A_CPU		1
72abff
@@ -58,6 +58,7 @@
72abff
 #define A_HUGE		34
72abff
 #define A_PWR_WGHFREQ	35
72abff
 #define A_PWR_USB	36
72abff
+#define A_FILESYSTEM	37
72abff
 
72abff
 
72abff
 /* Macro used to flag an activity that should be collected */
72abff
@@ -197,6 +198,7 @@
72abff
 #define NR_DISK_PREALLOC	3
72abff
 #define NR_FREQ_PREALLOC	0
72abff
 #define NR_USB_PREALLOC		5
72abff
+#define NR_FILESYSTEM_PREALLOC	3
72abff
 
72abff
 #define UTSNAME_LEN		65
72abff
 #define TIMESTAMP_LEN		64
72abff
@@ -706,6 +708,8 @@ extern __nr_t
72abff
 	wrap_get_freq_nr(struct activity *);
72abff
 extern __nr_t
72abff
 	wrap_get_usb_nr(struct activity *);
72abff
+extern __nr_t
72abff
+	wrap_get_filesystem_nr(struct activity *);
72abff
 	
72abff
 /* Functions used to read activities statistics */
72abff
 extern __read_funct_t
72abff
@@ -780,6 +784,8 @@ extern __read_funct_t
72abff
 	wrap_read_time_in_state(struct activity *);
72abff
 extern __read_funct_t
72abff
 	wrap_read_bus_usb_dev(struct activity *);
72abff
+extern __read_funct_t
72abff
+	wrap_read_filesystem(struct activity *);
72abff
 
72abff
 /* Other functions */
72abff
 extern void
72abff
diff --git a/sa_common.c b/sa_common.c
72abff
index 67c55db..3ccf24b 100644
72abff
--- a/sa_common.c
72abff
+++ b/sa_common.c
72abff
@@ -1282,6 +1282,10 @@ int parse_sar_opt(char *argv[], int *opt, struct activity *act[],
72abff
 			SELECT_ACTIVITY(A_DISK);
72abff
 			break;
72abff
 
72abff
+		case 'F':
72abff
+			SELECT_ACTIVITY(A_FILESYSTEM);
72abff
+			break;
72abff
+			
72abff
 		case 'H':
72abff
 			p = get_activity_position(act, A_HUGE);
72abff
 			act[p]->options   |= AO_SELECTED;
72abff
diff --git a/sa_wrap.c b/sa_wrap.c
72abff
index 321b227..298f889 100644
72abff
--- a/sa_wrap.c
72abff
+++ b/sa_wrap.c
72abff
@@ -847,6 +847,28 @@ __read_funct_t wrap_read_bus_usb_dev(struct activity *a)
72abff
 	return;
72abff
 }
72abff
 
72abff
+/*
72abff
+ ***************************************************************************
72abff
+ * Read filesystem statistics.
72abff
+ *
72abff
+ * IN:
72abff
+ * @a	Activity structure.
72abff
+ *
72abff
+ * OUT:
72abff
+ * @a	Activity structure with statistics.
72abff
+ ***************************************************************************
72abff
+ */
72abff
+__read_funct_t wrap_read_filesystem(struct activity *a)
72abff
+{
72abff
+	struct stats_filesystem *st_filesystem
72abff
+		= (struct stats_filesystem *) a->_buf0;
72abff
+
72abff
+	/* Read filesystems from /etc/mtab */
72abff
+	/* FIXME */
72abff
+
72abff
+	return;
72abff
+}
72abff
+
72abff
 /*
72abff
  ***************************************************************************
72abff
  * Count number of interrupts that are in /proc/stat file.
72abff
@@ -1049,3 +1071,24 @@ __nr_t wrap_get_usb_nr(struct activity *a)
72abff
 	
72abff
 	return 0;
72abff
 }
72abff
+
72abff
+/*
72abff
+ ***************************************************************************
72abff
+ * Get number of mounted filesystems from /etc/mtab. Don't take into account
72abff
+ * pseudo-filesystems.
72abff
+ *
72abff
+ * IN:
72abff
+ * @a	Activity structure.
72abff
+ *
72abff
+ * RETURNS:
72abff
+ * Number of filesystems + a pre-allocation constant.
72abff
+ ***************************************************************************
72abff
+ */
72abff
+__nr_t wrap_get_filesystem_nr(struct activity *a)
72abff
+{
72abff
+	__nr_t n = 0;
72abff
+
72abff
+	/* FIXME */
72abff
+
72abff
+	return 0;
72abff
+}
72abff
diff --git a/sar.c b/sar.c
72abff
index 8dd998b..2674810 100644
72abff
--- a/sar.c
72abff
+++ b/sar.c
72abff
@@ -107,7 +107,7 @@ void usage(char *progname)
72abff
 {
72abff
 	print_usage_title(stderr, progname);
72abff
 	fprintf(stderr, _("Options are:\n"
72abff
-			  "[ -A ] [ -B ] [ -b ] [ -C ] [ -d ] [ -H ] [ -h ] [ -p ] [ -q ] [ -R ]\n"
72abff
+			  "[ -A ] [ -B ] [ -b ] [ -C ] [ -d ] [ -F ] [ -H ] [ -h ] [ -p ] [ -q ] [ -R ]\n"
72abff
 			  "[ -r ] [ -S ] [ -t ] [ -u [ ALL ] ] [ -V ] [ -v ] [ -W ] [ -w ] [ -y ]\n"
72abff
 			  "[ -I { <int> [,...] | SUM | ALL | XALL } ] [ -P { <cpu> [,...] | ALL } ]\n"
72abff
 			  "[ -m { <keyword> [,...] | ALL } ] [ -n { <keyword> [,...] | ALL } ]\n"
72abff
@@ -132,6 +132,7 @@ void display_help(char *progname)
72abff
 	printf(_("\t-b\tI/O and transfer rate statistics\n"));
72abff
 	printf(_("\t-B\tPaging statistics\n"));
72abff
 	printf(_("\t-d\tBlock device statistics\n"));
72abff
+	printf(_("\t-F\tFilesystems statistics\n"));
72abff
 	printf(_("\t-H\tHugepages utilization statistics\n"));
72abff
 	printf(_("\t-I { <int> | SUM | ALL | XALL }\n"
72abff
 		 "\t\tInterrupts statistics\n"));
72abff
diff --git a/xml_stats.c b/xml_stats.c
72abff
index 66a6850..0a15f98 100644
72abff
--- a/xml_stats.c
72abff
+++ b/xml_stats.c
72abff
@@ -1989,4 +1989,21 @@ close_xml_markup:
72abff
 	if (CLOSE_MARKUP(a->options)) {
72abff
 		xml_markup_power_management(tab, CLOSE_XML_MARKUP);
72abff
 	}
72abff
-}
72abff
\ No newline at end of file
72abff
+}
72abff
+
72abff
+/*
72abff
+ ***************************************************************************
72abff
+ * Display filesystems statistics in XML.
72abff
+ *
72abff
+ * IN:
72abff
+ * @a		Activity structure with statistics.
72abff
+ * @curr	Index in array for current sample statistics.
72abff
+ * @tab		Indentation in XML output.
72abff
+ * @itv		Interval of time in jiffies.
72abff
+ ***************************************************************************
72abff
+ */
72abff
+__print_funct_t xml_print_filesystem_stats(struct activity *a, int curr, int tab,
72abff
+					   unsigned long long itv)
72abff
+{
72abff
+	/* FIXME */
72abff
+}
72abff
diff --git a/xml_stats.h b/xml_stats.h
72abff
index 3009860..6258703 100644
72abff
--- a/xml_stats.h
72abff
+++ b/xml_stats.h
72abff
@@ -87,5 +87,7 @@ extern __print_funct_t xml_print_pwr_wghfreq_stats
72abff
 	(struct activity *, int, int, unsigned long long);
72abff
 extern __print_funct_t xml_print_pwr_usb_stats
72abff
 	(struct activity *, int, int, unsigned long long);
72abff
+extern __print_funct_t xml_print_filesystem_stats
72abff
+	(struct activity *, int, int, unsigned long long);
72abff
 
72abff
 #endif /* _XML_STATS_H */
72abff
-- 
72abff
2.14.3
72abff