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

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