Browse Source

tsilo: added module's satistics

Federico Cabiddu 10 years ago
parent
commit
c89ae44d38
5 changed files with 95 additions and 37 deletions
  1. 4 0
      modules/tsilo/Makefile
  2. 6 2
      modules/tsilo/ts_append.c
  3. 15 2
      modules/tsilo/ts_hash.c
  4. 6 0
      modules/tsilo/ts_hash.h
  5. 64 33
      modules/tsilo/tsilo.c

+ 4 - 0
modules/tsilo/Makefile

@@ -8,8 +8,12 @@ include ../../Makefile.defs
 auto_gen=
 NAME=tsilo.so
 LIBS=
+
 DEFS+=-DKAMAILIO_MOD_INTERFACE
 
+SERLIBPATH=../../lib
+SER_LIBS+=$(SERLIBPATH)/kcore/kcore
+
 ifeq ($(INSTALL_FLAVOUR),kamailio)
 DEFS+= -DWITH_EVENT_LOCAL_REQUEST
 endif # INSTALL_FLAVOUR

+ 6 - 2
modules/tsilo/ts_append.c

@@ -28,7 +28,7 @@
 #include "../../mod_fix.h"
 #include "../../route.h"
 #include "../../data_lump.h"
-#include "../../lib/kcore/kstats_wrapper.h"
+#include "../../lib/kcore/statistics.h"
 #include "../../dset.h"
 #include "../../script_cb.h"
 #include "../../parser/msg_parser.h"
@@ -42,6 +42,7 @@ int ts_append(struct sip_msg* msg, str *ruri, char *table) {
 	ts_transaction_t* ptr;
 
 	int res;
+	int appended;
 
 	lock_entry_by_ruri(ruri);
 
@@ -57,7 +58,10 @@ int ts_append(struct sip_msg* msg, str *ruri, char *table) {
 
 	while(ptr) {
 		LM_DBG("transaction %u:%u found for %.*s, going to append branches\n",ptr->tindex, ptr->tlabel, ruri->len, ruri->s);
-		ts_append_to(msg, ptr->tindex, ptr->tlabel, table);
+
+		appended = ts_append_to(msg, ptr->tindex, ptr->tlabel, table);
+		if (appended > 0)
+			update_stat(added_branches, appended);
 		ptr = ptr->next;
 	}
 

+ 15 - 2
modules/tsilo/ts_hash.c

@@ -34,6 +34,7 @@
 #include "../../ut.h"
 #include "../../hashes.h"
 #include "../../lib/kmi/mi.h"
+#include "../../lib/kcore/statistics.h"
 #include "ts_hash.h"
 #include "ts_handlers.h"
 
@@ -256,6 +257,10 @@ int insert_ts_urecord(str* ruri, ts_urecord_t** _r)
 	}
 	entry->n++;
 	(*_r)->entry = entry;
+
+	update_stat(stored_ruris, 1);
+	update_stat(total_ruris, 1);
+
 	LM_DBG("urecord entry %p",entry);
 	return 0;
 }
@@ -281,6 +286,8 @@ void remove_ts_urecord(ts_urecord_t* _r)
                 entry->first = entry->last = NULL;
 	}
 
+	update_stat(stored_ruris, -1);
+
 	entry->n--;
 	free_ts_urecord(_r);
 
@@ -297,7 +304,7 @@ void remove_ts_urecord(ts_urecord_t* _r)
 int insert_ts_transaction(struct cell* t, struct sip_msg* msg, struct ts_urecord* _r)
 {
 	ts_transaction_t *ptr, *prev;
-    ts_transaction_t* ts;
+	ts_transaction_t* ts;
 
 	unsigned int tindex;
 	unsigned int tlabel;
@@ -318,7 +325,7 @@ int insert_ts_transaction(struct cell* t, struct sip_msg* msg, struct ts_urecord
 	}
 
 	if ( (ts=new_ts_transaction(tindex, tlabel) ) == 0) {
-		LM_ERR("failed to create new contact\n");
+		LM_ERR("failed to create new transaction\n");
 		return -1;
 	}
 
@@ -335,6 +342,10 @@ int insert_ts_transaction(struct cell* t, struct sip_msg* msg, struct ts_urecord
 	if (ts_set_tm_callbacks(t, msg, ts) < 0) {
 		LM_ERR("failed to set transaction %d:%d callbacks\n", tindex, tlabel);
 	}
+
+	update_stat(stored_transactions, 1);
+	update_stat(total_transactions, 1);
+
 	return 0;
 }
 /*!
@@ -399,6 +410,8 @@ void remove_ts_transaction(ts_transaction_t* ts_t)
 	if (ts_t->urecord->transactions == ts_t)
 		ts_t->urecord->transactions = ts_t->next;
 
+	update_stat(stored_transactions, -1);
+
 	free_ts_transaction((void*)ts_t);
 
 	return;

+ 6 - 0
modules/tsilo/ts_hash.h

@@ -36,6 +36,12 @@
 #define MAX_TS_LOCKS  2048
 #define MIN_TS_LOCKS  2
 
+stat_var *stored_ruris;
+stat_var *stored_transactions;
+stat_var *total_ruris;
+stat_var *total_transactions;
+stat_var *added_branches;
+
 typedef struct ts_transaction
 {
 	unsigned int		tindex;		/*!< transaction index */

+ 64 - 33
modules/tsilo/tsilo.c

@@ -1,6 +1,6 @@
 /**
  *
- * Copyright (C) 2014 Federico Cabiddu ([email protected])
+ * Copyright (C) 2015 Federico Cabiddu ([email protected])
  *
  * This file is part of Kamailio, a free SIP server.
  *
@@ -33,6 +33,7 @@
 #include "../../modules/usrloc/usrloc.h"
 #include "../../dset.h"
 #include "../../rpc_lookup.h"
+#include "../../lib/kcore/statistics.h"
 
 #include "ts_hash.h"
 #include "ts_handlers.h"
@@ -63,8 +64,15 @@ static int w_ts_append_to(struct sip_msg* msg, char *idx, char *lbl, char *d);
 static int fixup_ts_append_to(void** param, int param_no);
 static int w_ts_append(struct sip_msg* _msg, char *_table, char *_ruri);
 static int fixup_ts_append(void** param, int param_no);
+
 static int w_ts_store(struct sip_msg* msg);
 
+extern stat_var *stored_ruris;
+extern stat_var *stored_transactions;
+extern stat_var *total_ruris;
+extern stat_var *total_transactions;
+extern stat_var *added_branches;
+
 static cmd_export_t cmds[]={
 	{"ts_append_to", (cmd_function)w_ts_append_to,  3,
 		fixup_ts_append_to, 0, REQUEST_ROUTE | FAILURE_ROUTE },
@@ -72,7 +80,7 @@ static cmd_export_t cmds[]={
 		fixup_ts_append, 0, REQUEST_ROUTE | FAILURE_ROUTE },
 	{"ts_store", (cmd_function)w_ts_store,  0,
 		0 , 0, REQUEST_ROUTE | FAILURE_ROUTE },
-	{0,0,0,0,0}
+	{0,0,0,0,0,0}
 };
 
 static param_export_t params[]={
@@ -80,21 +88,36 @@ static param_export_t params[]={
 	{0,0,0}
 };
 
+#ifdef STATISTICS
+/*! \brief We expose internal variables via the statistic framework below.*/
+stat_export_t mod_stats[] = {
+	{"stored_ruris",	STAT_NO_RESET, 	&stored_ruris  },
+	{"stored_transactions",	STAT_NO_RESET, 	&stored_transactions  },
+	{"total_ruris",		STAT_NO_RESET, 	&total_ruris  },
+	{"total_transactions",	STAT_NO_RESET, 	&total_transactions  },
+	{"added_branches",	STAT_NO_RESET, 	&added_branches  },
+	{0, 0, 0}
+};
+#endif
 
 /** module exports */
-struct module_exports exports= {
+struct module_exports exports = {
 	"tsilo",
-    DEFAULT_DLFLAGS,
-	cmds,
-	params,
-	0, /* exported statistics */
-    0,    /* exported MI functions */
-    0,
-    0,
-	mod_init,   /* module initialization function */
+	DEFAULT_DLFLAGS,/* dlopen flags */
+	cmds,        	/* Exported functions */
+	params,      	/* Exported parameters */
+#ifdef STATISTICS
+	mod_stats,   	/* exported statistics */
+#else
+	0,
+#endif
+	0,           	/* exported MI functions */
+	0,     		/* exported pseudo-variables */
+	0,           	/* extra processes */
+	mod_init,    	/* module initialization function */
 	0,
-	(destroy_function) destroy,  /* destroy function */
-	0
+	destroy, 	/* destroy function */
+	0,  		/* Per-child init function */
 };
 
 /**
@@ -107,10 +130,10 @@ static int mod_init(void)
 
 	/* register the RPC methods */
 	if(rpc_register_array(rpc_methods)!=0)
-    {
+	{
         LM_ERR("failed to register RPC commands\n");
         return -1;
-    }
+	}
 	/* load the TM API */
 	if (load_tm_api(&_tmb)!=0) {
 		LM_ERR("can't load TM API\n");
@@ -137,25 +160,25 @@ static int mod_init(void)
 
 	use_domain = _ul.use_domain;
 	/* sanitize hash_size */
-    if (hash_size < 1){
-        LM_WARN("hash_size is smaller "
-				"than 1  -> rounding from %d to 1\n",
-                hash_size);
-        hash_size = 1;
-    }
-
-    /* initialize the hash table */
-    for( n=0 ; n<(8*sizeof(n)) ; n++) {
-        if (hash_size==(1<<n))
-            break;
-        if (n && hash_size<(1<<n)) {
-            LM_WARN("hash_size is not a power "
-                "of 2 as it should be -> rounding from %d to %d (n=%d)\n",
-                hash_size, 1<<(n-1), n);
-            hash_size = 1<<(n-1);
+	if (hash_size < 1){
+		LM_WARN("hash_size is smaller "
+			"than 1  -> rounding from %d to 1\n",
+			hash_size);
+		hash_size = 1;
+	}
+
+	/* initialize the hash table */
+	for( n=0 ; n<(8*sizeof(n)) ; n++) {
+		if (hash_size==(1<<n))
 			break;
-        }
-    }
+		if (n && hash_size<(1<<n)) {
+			LM_WARN("hash_size is not a power "
+				"of 2 as it should be -> rounding from %d to %d (n=%d)\n",
+				hash_size, 1<<(n-1), n);
+			hash_size = 1<<(n-1);
+			break;
+		}
+	}
 
 	LM_DBG("creating table with size %d", hash_size);
 	if ( init_ts_table(hash_size)<0 ) {
@@ -163,7 +186,15 @@ static int mod_init(void)
 		return -1;
 	}
 
+#ifdef STATISTICS
+	/* register statistics */
+	if (register_module_stats(exports.name, mod_stats)!=0 ) {
+		LM_ERR("failed to register core statistics\n");
+		return -1;
+	}
 	return 0;
+#endif
+
 }
 
 /**