[sr-dev] git:master: mtree: exposed internal usage data via mi

Daniel-Constantin Mierla miconda at gmail.com
Fri Oct 1 15:37:43 CEST 2010


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

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date:   Fri Oct  1 15:36:50 2010 +0200

mtree: exposed internal usage data via mi

- good for troubleshooting memory usage

---

 modules/mtree/README              |   33 ++++++++++++++++------
 modules/mtree/doc/mtree_admin.xml |   20 +++++++++++++
 modules/mtree/mtree.c             |    6 ++++
 modules/mtree/mtree.h             |    3 ++
 modules/mtree/mtree_mod.c         |   55 +++++++++++++++++++++++++++++++++++++
 5 files changed, 108 insertions(+), 9 deletions(-)

diff --git a/modules/mtree/README b/modules/mtree/README
index f11bac1..7aaa4fd 100644
--- a/modules/mtree/README
+++ b/modules/mtree/README
@@ -10,7 +10,7 @@ Daniel-Constantin Mierla
 
    <miconda at gmail.com>
 
-   Copyright © 2010 Daniel-Constantin Mierla (asipto.com)
+   Copyright © 2010 Daniel-Constantin Mierla (asipto.com)
      __________________________________________________________________
 
    Table of Contents
@@ -44,6 +44,7 @@ Daniel-Constantin Mierla
 
               5.1. mt_list
               5.2. mt_reload
+              5.3. mt_summary
 
    List of Examples
 
@@ -90,6 +91,7 @@ Chapter 1. Admin Guide
 
         5.1. mt_list
         5.2. mt_reload
+        5.3. mt_summary
 
 1. Overview
 
@@ -129,7 +131,7 @@ Chapter 1. Admin Guide
 
    URL of the database server to be used.
 
-   Default value is "mysql://openser:openserrw@localhost/openser".
+   Default value is “mysql://openser:openserrw@localhost/openser”.
 
    Example 1.1. Set db_url parameter
 ...
@@ -141,7 +143,7 @@ modparam("mtree", "db_url", "dbdriver://username:password@dbhost/dbname")
    Name of DB table where data for trees is store. It is ignored if a
    'mtree' parameter is defined.
 
-   Default value is "mtrees".
+   Default value is “mtrees”.
 
    Example 1.2. Set db_table parameter
 ...
@@ -152,7 +154,7 @@ modparam("mtree", "db_table", "mymtrees")
 
    Definition of memory tree
 
-   Default value is "none".
+   Default value is “none”.
 
    Example 1.3. Set mtree parameter
 ...
@@ -163,7 +165,7 @@ modparam("mtree", "mtree", "name=mytable;dbtable=routes;type=0;")
 
    Name of 'tname' column.
 
-   Default value is "tname".
+   Default value is “tname”.
 
    Example 1.4. Set tname_column parameter
 ...
@@ -174,7 +176,7 @@ modparam("mtree", "tname_column", "name")
 
    Name of 'tprefix' column.
 
-   Default value is "tprefix".
+   Default value is “tprefix”.
 
    Example 1.5. Set tprefix_column parameter
 ...
@@ -185,7 +187,7 @@ modparam("mtree", "tprefix_column", "prefix")
 
    Name of 'tvalue' column.
 
-   Default value is "tvalue".
+   Default value is “tvalue”.
 
    Example 1.6. Set tvalue_column parameter
 ...
@@ -207,7 +209,7 @@ modparam("mtree", "fetch_rows", 4000)
 
    The list with characters allowed in prefix.
 
-   Default value is "0123456789".
+   Default value is “0123456789”.
 
    Example 1.8. Set char_list parameter
 ...
@@ -219,7 +221,7 @@ modparam("mtree", "char_list", "0123456789*+")
    The PV spec where to store the matched value. It can be any writtable
    PV.
 
-   Default value is "$avp(s:tvalue)".
+   Default value is “$avp(s:tvalue)”.
 
    Example 1.9. Set pv_value parameter
 ...
@@ -255,6 +257,7 @@ mt_match("mytree", "$rU", "0");
 
    5.1. mt_list
    5.2. mt_reload
+   5.3. mt_summary
 
 5.1.  mt_list
 
@@ -284,3 +287,15 @@ mt_match("mytree", "$rU", "0");
                 :mt_reload:_reply_fifo_file_
                 _mtname_
                 _empty_line_
+
+5.3.  mt_summary
+
+   List usage summary for all trees.
+
+   Name: mt_summary
+
+   Parameters: none.
+
+   MI FIFO Command Format:
+                :mt_summary:_reply_fifo_file_
+                _empty_line_
diff --git a/modules/mtree/doc/mtree_admin.xml b/modules/mtree/doc/mtree_admin.xml
index f4b9698..64e4c00 100644
--- a/modules/mtree/doc/mtree_admin.xml
+++ b/modules/mtree/doc/mtree_admin.xml
@@ -329,6 +329,26 @@ mt_match("mytree", "$rU", "0");
 		_empty_line_
 		</programlisting>
     </section>
+
+	<section>
+		<title>
+		<function moreinfo="none">mt_summary</function>
+		</title>
+		<para>
+		List usage summary for all trees.
+		</para>
+		<para>
+		Name: <emphasis>mt_summary</emphasis>
+		</para>
+		<para>Parameters: none.</para>
+		<para>
+		MI FIFO Command Format:
+		</para>
+        <programlisting  format="linespecific">
+		:mt_summary:_reply_fifo_file_
+		_empty_line_
+		</programlisting>
+    </section>
     </section>
 
 </chapter>
diff --git a/modules/mtree/mtree.c b/modules/mtree/mtree.c
index f88c9e5..84a798d 100644
--- a/modules/mtree/mtree.c
+++ b/modules/mtree/mtree.c
@@ -162,6 +162,8 @@ int mt_add_to_tree(m_tree_t *pt, str *sp, str *sv)
 			return -1;
 		}
 		memset(pt->head, 0, MT_NODE_SIZE*sizeof(mt_node_t));
+		pt->nrnodes++;
+		pt->memsize +=  MT_NODE_SIZE*sizeof(mt_node_t);
 	}
 
 	itn0 = pt->head;
@@ -184,6 +186,8 @@ int mt_add_to_tree(m_tree_t *pt, str *sp, str *sv)
 				return -1;
 			}
 			memset(itn, 0, MT_NODE_SIZE*sizeof(mt_node_t));
+			pt->nrnodes++;
+			pt->memsize +=  MT_NODE_SIZE*sizeof(mt_node_t);
 			itn0[_mt_char_table[(unsigned int)sp->s[l]]].child = itn;
 		}
 		l++;	
@@ -213,6 +217,8 @@ int mt_add_to_tree(m_tree_t *pt, str *sp, str *sv)
 		LM_ERR("no more shm mem!\n");
 		return -1;
 	}
+	pt->memsize +=  (sv->len+1)*sizeof(char);
+	pt->nritems++;
 	strncpy(itn0[_mt_char_table[(unsigned int)sp->s[l]]].tvalue.s, sv->s,
 			sv->len);
 	itn0[_mt_char_table[(unsigned int)sp->s[l]]].tvalue.len = sv->len;
diff --git a/modules/mtree/mtree.h b/modules/mtree/mtree.h
index 0bacb90..8cbe006 100644
--- a/modules/mtree/mtree.h
+++ b/modules/mtree/mtree.h
@@ -54,6 +54,9 @@ typedef struct _m_tree
 	str tname;
 	str dbtable;
 	int type;
+	unsigned int nrnodes;
+	unsigned int nritems;
+	unsigned int memsize;
 	mt_node_t *head;
 
 	struct _m_tree *next;
diff --git a/modules/mtree/mtree_mod.c b/modules/mtree/mtree_mod.c
index 2ab5ae5..e89987a 100644
--- a/modules/mtree/mtree_mod.c
+++ b/modules/mtree/mtree_mod.c
@@ -111,6 +111,7 @@ static int mt_match(struct sip_msg *msg, gparam_t *dm, gparam_t *var,
 
 static struct mi_root* mt_mi_reload(struct mi_root*, void* param);
 static struct mi_root* mt_mi_list(struct mi_root*, void* param);
+static struct mi_root* mt_mi_summary(struct mi_root*, void* param);
 
 static int mt_load_db(str *tname);
 static int mt_load_db_trees();
@@ -141,6 +142,7 @@ static param_export_t params[]={
 static mi_export_t mi_cmds[] = {
 	{ "mt_reload",  mt_mi_reload,  0,  0,  child_init },
 	{ "mt_list",    mt_mi_list,    0,  0,  0 },
+	{ "mt_summary", mt_mi_summary, 0,  0,  0 },
 	{ 0, 0, 0, 0, 0}
 };
 
@@ -886,3 +888,56 @@ error:
 	return 0;
 }
 
+struct mi_root* mt_mi_summary(struct mi_root* cmd_tree, void* param)
+{
+	m_tree_t *pt;
+	struct mi_root* rpl_tree = NULL;
+	struct mi_node* node = NULL;
+	struct mi_attr* attr= NULL;
+	str val;
+
+	if(!mt_defined_trees())
+	{
+		LM_ERR("empty tree list\n");
+		return init_mi_tree( 500, "No trees", 8);
+	}
+
+	rpl_tree = init_mi_tree(200, MI_OK_S, MI_OK_LEN);
+	if(rpl_tree == NULL)
+		return 0;
+
+	pt = mt_get_first_tree();
+
+	while(pt!=NULL)
+	{
+		node = add_mi_node_child(&rpl_tree->node, 0, "MT", 2, 0, 0);
+		if(node == NULL)
+			goto error;
+		attr = add_mi_attr(node, MI_DUP_VALUE, "TNAME", 5,
+				pt->tname.s, pt->tname.len);
+		if(attr == NULL)
+			goto error;
+		val.s = int2str(pt->memsize, &val.len);
+		attr = add_mi_attr(node, MI_DUP_VALUE, "MEMSIZE", 7,
+				val.s, val.len);
+		if(attr == NULL)
+			goto error;
+		val.s = int2str(pt->nrnodes, &val.len);
+		attr = add_mi_attr(node, MI_DUP_VALUE, "NRNODES", 7,
+				val.s, val.len);
+		if(attr == NULL)
+			goto error;
+		val.s = int2str(pt->nritems, &val.len);
+		attr = add_mi_attr(node, MI_DUP_VALUE, "NRITEMS", 7,
+				val.s, val.len);
+		if(attr == NULL)
+			goto error;
+
+		pt = pt->next;
+	}
+
+	return rpl_tree;
+error:
+	free_mi_tree(rpl_tree);
+	return 0;
+}




More information about the sr-dev mailing list