[sr-dev] git:master: htbale: added rpc command htable.stats

Elena-Ramona Modroiu ramona at rosdev.ro
Mon Aug 19 17:47:16 CEST 2013


Module: sip-router
Branch: master
Commit: d33106994516e27944657c3bf17c3ccb5a521a50
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=d33106994516e27944657c3bf17c3ccb5a521a50

Author: Elena-Ramona Modroiu <ramona at asipto.com>
Committer: Elena-Ramona Modroiu <ramona at asipto.com>
Date:   Mon Aug 19 17:39:26 2013 +0200

htbale: added rpc command htable.stats

- print stats about htables: name, number of slots, number of items, max
  number of items per slot, min number of items per slot

---

 modules/htable/htable.c |   59 +++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 59 insertions(+), 0 deletions(-)

diff --git a/modules/htable/htable.c b/modules/htable/htable.c
index 37c68f4..5dba9e0 100644
--- a/modules/htable/htable.c
+++ b/modules/htable/htable.c
@@ -632,6 +632,10 @@ static const char* htable_list_doc[2] = {
 	"List all htables.",
 	0
 };
+static const char* htable_stats_doc[2] = {
+	"Statistics about htables.",
+	0
+};
 static const char* htable_reload_doc[2] = {
 	"Reload hash table.",
 	0
@@ -900,6 +904,60 @@ error:
 	return;
 }
 
+static void  htable_rpc_stats(rpc_t* rpc, void* c)
+{
+	ht_t *ht;
+	void* th;
+	unsigned int min;
+	unsigned int max;
+	unsigned int all;
+	unsigned int i;
+
+	ht = ht_get_root();
+	if(ht==NULL)
+	{
+		rpc->fault(c, 500, "No htables");
+		return;
+	}
+	while (ht != NULL)
+	{
+		/* add entry node */
+		if (rpc->add(c, "{", &th) < 0)
+		{
+			rpc->fault(c, 500, "Internal error creating structure rpc");
+			goto error;
+		}
+		all = 0;
+		max = 0;
+		min = 4294967295U;
+		for(i=0; i<ht->htsize; i++) {
+			lock_get(&ht->entries[i].lock);
+			if(ht->entries[i].esize<min)
+				min = ht->entries[i].esize;
+			if(ht->entries[i].esize>max)
+				max = ht->entries[i].esize;
+			all += ht->entries[i].esize;
+			lock_release(&ht->entries[i].lock);
+		}
+
+		if(rpc->struct_add(th, "Sddd",
+						"name", &ht->name,	/* str */
+						"slots", (int)ht->htsize,	/* uint */
+						"all", (int)all,	/* uint */
+						"min", (int)min,	/* uint */
+						"max", (int)max		/* uint */
+						) < 0) {
+			rpc->fault(c, 500, "Internal error creating rpc structure");
+			goto error;
+		}
+		ht = ht->next;
+	}
+
+error:
+	return;
+}
+
+
 /*! \brief RPC htable.reload command to reload content of a hash table */
 static void htable_rpc_reload(rpc_t* rpc, void* c)
 {
@@ -986,6 +1044,7 @@ rpc_export_t htable_rpc[] = {
 	{"htable.seti", htable_rpc_seti, htable_seti_doc, 0},
 	{"htable.listTables", htable_rpc_list, htable_list_doc, 0},
 	{"htable.reload", htable_rpc_reload, htable_reload_doc, 0},
+	{"htable.stats", htable_rpc_stats, htable_stats_doc, 0},
 	{0, 0, 0, 0}
 };
 




More information about the sr-dev mailing list