Browse code

kex(k): updated to the lastest statistics changes

kex used some lower-level statistics access (some of the functions
and data types that were deleted) and required some minor updates.

Andrei Pelinescu-Onciul authored on 08/08/2010 17:47:06
Showing 2 changed files
... ...
@@ -201,14 +201,12 @@ int register_core_stats(void)
201 201
 inline static int mi_add_stat(struct mi_node *rpl, stat_var *stat)
202 202
 {
203 203
 	struct mi_node *node;
204
-	stats_collector *sc;
205 204
 
206
-	if((sc = get_stats_collector())==NULL) return -1;
205
+	if (stats_support()==0) return -1;
207 206
 
208
-	node = addf_mi_node_child(rpl, 0, 0, 0, "%.*s:%.*s = %lu",
209
-		sc->amodules[stat->mod_idx].name.len,
210
-		sc->amodules[stat->mod_idx].name.s,
211
-		stat->name.len, stat->name.s,
207
+	node = addf_mi_node_child(rpl, 0, 0, 0, "%s:%s = %lu",
208
+		ZSW(get_stat_module(stat)),
209
+		ZSW(get_stat_name(stat)),
212 210
 		get_stat_val(stat) );
213 211
 
214 212
 	if (node==0)
... ...
@@ -216,37 +214,36 @@ inline static int mi_add_stat(struct mi_node *rpl, stat_var *stat)
216 216
 	return 0;
217 217
 }
218 218
 
219
-inline static int mi_add_module_stats(struct mi_node *rpl,
220
-													module_stats *mods)
219
+
220
+
221
+/* callback for counter_iterate_grp_vars. */
222
+static void mi_add_grp_vars_cbk(void* r, str* g, str* n, counter_handle_t h)
221 223
 {
224
+	struct mi_node *rpl;
222 225
 	struct mi_node *node;
223
-	stat_var *stat;
224
-
225
-	for( stat=mods->head ; stat ; stat=stat->lnext) {
226
-		node = addf_mi_node_child(rpl, 0, 0, 0, "%.*s:%.*s = %lu",
227
-			mods->name.len, mods->name.s,
228
-			stat->name.len, stat->name.s,
229
-			get_stat_val(stat) );
230
-		if (node==0)
231
-			return -1;
232
-	}
233
-	return 0;
226
+	
227
+	rpl = r;
228
+	node = addf_mi_node_child(rpl, 0, 0, 0, "%.*s:%.*s = %lu",
229
+							g->len, g->s, n->len, n->s, counter_get_val(h));
234 230
 }
235 231
 
236 232
 
233
+/* callback for counter_iterate_grp_names */
234
+static void mi_add_all_grps_cbk(void* p, str* g)
235
+{
236
+	counter_iterate_grp_vars(g->s, mi_add_grp_vars_cbk, p);
237
+}
238
+
237 239
 static struct mi_root *mi_get_stats(struct mi_root *cmd, void *param)
238 240
 {
239 241
 	struct mi_root *rpl_tree;
240 242
 	struct mi_node *rpl;
241 243
 	struct mi_node *arg;
242
-	module_stats   *mods;
243 244
 	stat_var       *stat;
244 245
 	str val;
245
-	int i;
246 246
 
247
-	stats_collector *sc;
248 247
 
249
-	if((sc = get_stats_collector())==NULL)
248
+	if(stats_support()==0)
250 249
 		return init_mi_tree( 404, "Statistics Not Found", 20);
251 250
 
252 251
 	if (cmd->node.kids==NULL)
... ...
@@ -265,18 +262,15 @@ static struct mi_root *mi_get_stats(struct mi_root *cmd, void *param)
265 265
 
266 266
 		if ( val.len==3 && memcmp(val.s,"all",3)==0) {
267 267
 			/* add all statistic variables */
268
-			for( i=0 ; i<sc->mod_no ;i++ ) {
269
-				if (mi_add_module_stats( rpl, &sc->amodules[i] )!=0)
270
-					goto error;
271
-			}
268
+			/* use direct counters access for that */
269
+			counter_iterate_grp_names(mi_add_all_grps_cbk, rpl);
272 270
 		} else if ( val.len>1 && val.s[val.len-1]==':') {
273 271
 			/* add module statistics */
274 272
 			val.len--;
275
-			mods = get_stat_module( &val );
276
-			if (mods==0)
277
-				continue;
278
-			if (mi_add_module_stats( rpl, mods )!=0)
279
-				goto error;
273
+			val.s[val.len]=0; /* zero term. */
274
+			/* use direct counters access for that */
275
+			counter_iterate_grp_vars(val.s, mi_add_grp_vars_cbk, rpl);
276
+			val.s[val.len]=':' /* restore */;
280 277
 		} else {
281 278
 			/* add only one statistic */
282 279
 			stat = get_stat( &val );
... ...
@@ -124,9 +124,6 @@ static int mod_init(void)
124 124
  */
125 125
 static void destroy(void)
126 126
 {
127
-#ifdef STATISTICS
128
-	destroy_stats_collector();
129
-#endif
130 127
 	return;
131 128
 }
132 129