Skip to contentSkip to conversation

statistics: sets of statistics in single file

RFC PATCH In review Martin Peschke 1 participant 1 message Jun 6, 2007

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

RFC PATCH 3/4 statistics: sets of statistics in single file

This patch chips a structure describing a set of statistics from the structure used to manage the user interface (files) for a set of statistics. The benefit of this split and small API change is that users can have multiple sets of statistics per file.

For example, a user which reports statistics data for many entities of similar type can have them all represented in the same file now:

my_entity_1 some_statistic 0x1000 67
my_entity_1 some_statistic 0x4000 52
my_entity_1 some_statistic 0x5000 13
my_entity_1 some_statistic other 4
my_entity_1 another_statistic samples 83
my_entity_1 another_statistic minimum 185
my_entity_1 another_statistic average 2875.763
my_entity_1 another_statistic maximum 2837585
my_entity_1 another_statistic variance 298469.485
my_entity_2 some_statistic other 0
my_entity_2 another_statistic samples 0
my_entity_2 another_statistic minimum 0
my_entity_2 another_statistic average 0.000
my_entity_2 another_statistic maximum 0
my_entity_2 another_statistic variance 0.000

---

 include/linux/statistic.h |   47 ++++
 lib/statistic.c           |  444 ++++++++++++++++++++++++++++------------------
 2 files changed, 315 insertions(+), 176 deletions(-)
include/linux/statistic.h +39 -8
Index: linux/include/linux/statistic.h
===================================================================
@@ -108,13 +108,34 @@ struct statistic {
 };
 
 /**
- * struct statistic_ui - collection of statistics for an entity
+ * struct statistic_coll - collection of statistics for an entity
  * @stat: a struct statistic array
  * @info: a struct statistic_info array describing the struct statistic array
  * @number: number of entries in both arrays
- * @pull: an optional function called when user reads data from file
+ * @private: optional data pointer reserved for use by clients
  * @label: an optional function retrieving a label for each statistics entry
+ *
+ * Exploiters must setup a struct statistic_coll prior to calling
+ * statistic_attach().
+ */
+struct statistic_coll {
+/* private: */
+	struct list_head	 list;
+/* public: */
+#define STATISTIC_COLL_NAME_SIZE 64
+	char 			 name[STATISTIC_COLL_NAME_SIZE];
+	struct statistic	*stat;
+	struct statistic_info	*info;
+	int			 number;
+	void			*private;
+	void			(*label)(struct statistic_coll *coll, int i,
+					 void *key, char *buf, int size);
+};
+
+/**
+ * struct statistic_ui - user interface for statistics
  * @private: optional data pointer reserved for use by clients
+ * @pull: an optional function called when user reads data from file
  *
  * Exploiters must setup a struct statistic_ui prior to calling
  * statistic_create().
@@ -122,17 +143,13 @@ struct statistic {
 struct statistic_ui {
 /* private: */
 	struct list_head	 list;
+	struct list_head	 coll_list;
 	void			*dir;
 	void			*data;
 	void			*def;
 /* public: */
-	struct statistic	*stat;
-	struct statistic_info	*info;
-	int			 number;
-	void			(*pull)(struct statistic_ui *ui);
-	void			(*label)(struct statistic_ui *ui,
-					 int i, void *key, char *buf, int size);
 	void			*private;
+	void			(*pull)(struct statistic_ui *ui);
 };
 
 #ifdef CONFIG_STATISTICS
@@ -140,6 +157,9 @@ struct statistic_ui {
 extern int statistic_create(struct statistic_ui *, const char *);
 extern int statistic_remove(struct statistic_ui *);
 
+extern int statistic_attach(struct statistic_coll *, struct statistic_ui *);
+extern int statistic_detach(struct statistic_coll *);
+
 extern void statistic_set(struct statistic *, int, s64, u64);
 extern void statistic_set_key(struct statistic *, int, void *, u64);
 
@@ -323,6 +343,17 @@ static inline int statistic_remove(struc
 	return 0;
 }
 
+static inline int statistic_attach(struct statistic_coll *coll,
+				   struct statistic_ui *ui)
+{
+	return 0;
+}
+
+static inline int statistic_detach(struct statistic_coll *coll)
+{
+	return 0;
+}
+
 static inline void statistic_set(struct statistic *stat, int i,
 				 s64 value, u64 total)
 {
lib/statistic.c +276 -168

690 lines not on this page · raw message