<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Hi Paul,<br>
<br>
I committed the fix to return long value in get_stat_val(), soon I
will backport to 3.1 branch. I will add clear statistics mi command
as well.<br>
<br>
Thanks,<br>
Daniel<br>
<br>
On 3/29/11 3:59 PM, Paul Pankhurst wrote:
<blockquote cite="mid:67D65AF6C6364BE6926D01039A792042@pjplaptop"
type="cite">
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
<div dir="ltr">
<div style="font-family: 'Calibri'; color: rgb(0, 0, 0);
font-size: 12pt;">
<div>Hi Daniel,</div>
<div>Here is the svn diff output against the 3.1.2 version we
had in our local svn repo for the clear_stats command.</div>
<div> </div>
<div>Note I added this as a new command rather than
enhancement to the reset one to maintain backwards
compatibility.</div>
<div>This version outputs details of the values after
resetting them, with the old values in brackets so that you
can</div>
<div>a) see if a variable was read only and thus not reset</div>
<div>b) see the final counts at the point of resetting them
all</div>
<div> </div>
<div>Also it makes a call to the bodge function
get_stat_val_long in this code fragment.</div>
<div> </div>
<div>Regards</div>
<div> </div>
<div>Paul</div>
<div> </div>
<div>Index: core_stats.c</div>
<div>===================================================================</div>
<div>--- core_stats.c (revision 8)</div>
<div>+++ core_stats.c (working copy)</div>
<div>@@ -95,10 +95,12 @@</div>
<div> </div>
<div>static struct mi_root *mi_get_stats(struct mi_root *cmd,
void *param);</div>
<div>static struct mi_root *mi_reset_stats(struct mi_root
*cmd, void *param);</div>
<div>+static struct mi_root *mi_clear_stats(struct mi_root
*cmd, void *param);</div>
<div> </div>
<div>static mi_export_t mi_stat_cmds[] = {</div>
<div> { "get_statistics", mi_get_stats, 0 , 0,
0 },</div>
<div> { "reset_statistics", mi_reset_stats, 0 , 0,
0 },</div>
<div>+ { "clear_statistics", mi_clear_stats, 0 , 0,
0 },</div>
<div> { 0, 0, 0, 0, 0}</div>
<div>};</div>
<div> </div>
<div>@@ -207,15 +209,44 @@</div>
<div> node = addf_mi_node_child(rpl, 0, 0, 0, "%s:%s =
%lu",</div>
<div> ZSW(get_stat_module(stat)),</div>
<div> ZSW(get_stat_name(stat)),</div>
<div>- get_stat_val(stat) );</div>
<div>+ get_stat_val_long(stat) );</div>
<div> </div>
<div> if (node==0)</div>
<div> return -1;</div>
<div> return 0;</div>
<div>}</div>
<div> </div>
<div>+inline static int mi_reset_and_add_stat(struct mi_node
*rpl, stat_var *stat)</div>
<div>+{</div>
<div>+ struct mi_node *node;</div>
<div>+ long old_val, new_val;</div>
<div> </div>
<div>+ if (stats_support()==0) return -1;</div>
<div> </div>
<div>+ old_val=get_stat_val_long(stat);</div>
<div>+ reset_stat(stat);</div>
<div>+ new_val=get_stat_val_long(stat);</div>
<div>+</div>
<div>+ if (old_val==new_val)</div>
<div>+ {</div>
<div>+ node = addf_mi_node_child(rpl, 0, 0, 0,
"%s:%s = %lu",</div>
<div>+ ZSW(get_stat_module(stat)),</div>
<div>+ ZSW(get_stat_name(stat)),</div>
<div>+ new_val);</div>
<div>+ }</div>
<div>+ else</div>
<div>+ {</div>
<div>+ node = addf_mi_node_child(rpl, 0, 0, 0, "%s:%s
= %lu (%lu)",</div>
<div>+ ZSW(get_stat_module(stat)),</div>
<div>+ ZSW(get_stat_name(stat)),</div>
<div>+ new_val, old_val );</div>
<div>+ }</div>
<div>+</div>
<div>+ if (node==0)</div>
<div>+ return -1;</div>
<div>+ return 0;</div>
<div>+}</div>
<div>+</div>
<div>/* callback for counter_iterate_grp_vars. */</div>
<div>static void mi_add_grp_vars_cbk(void* r, str* g, str* n,
counter_handle_t h)</div>
<div>{</div>
<div>@@ -227,13 +258,43 @@</div>
<div>
g->len, g->s, n->len, n->s, counter_get_val(h));</div>
<div>}</div>
<div> </div>
<div>+/* callback for counter_iterate_grp_vars to reset
counters */</div>
<div>+static void mi_add_grp_vars_cbk2(void* r, str* g, str*
n, counter_handle_t h)</div>
<div>+{</div>
<div>+ struct mi_node *rpl;</div>
<div>+ struct mi_node *node;</div>
<div>+ counter_val_t old_val, new_val;</div>
<div>+</div>
<div>+ rpl = r;</div>
<div>+ old_val = counter_get_val(h);</div>
<div>+ counter_reset(h);</div>
<div>+ new_val = counter_get_val(h);</div>
<div> </div>
<div>+ if (old_val==new_val)</div>
<div>+ {</div>
<div>+ node = addf_mi_node_child(rpl, 0, 0, 0,
"%.*s:%.*s = %lu",</div>
<div>+
g->len, g->s, n->len, n->s, new_val);</div>
<div>+ }</div>
<div>+ else</div>
<div>+ {</div>
<div>+ node = addf_mi_node_child(rpl, 0, 0, 0,
"%.*s:%.*s = %lu (%lu)",</div>
<div>+
g->len, g->s, n->len, n->s, new_val, old_val);</div>
<div>+ }</div>
<div>+}</div>
<div>+</div>
<div>+</div>
<div>/* callback for counter_iterate_grp_names */</div>
<div>static void mi_add_all_grps_cbk(void* p, str* g)</div>
<div>{</div>
<div> counter_iterate_grp_vars(g->s,
mi_add_grp_vars_cbk, p);</div>
<div>}</div>
<div> </div>
<div>+/* callback for counter_iterate_grp_names to reset
counters */</div>
<div>+static void mi_add_all_grps_cbk2(void* p, str* g)</div>
<div>+{</div>
<div>+ counter_iterate_grp_vars(g->s,
mi_add_grp_vars_cbk2, p);</div>
<div>+}</div>
<div>+</div>
<div>static struct mi_root *mi_get_stats(struct mi_root *cmd,
void *param)</div>
<div>{</div>
<div> struct mi_root *rpl_tree;</div>
<div>@@ -293,7 +354,66 @@</div>
<div>}</div>
<div> </div>
<div> </div>
<div>+static struct mi_root *mi_clear_stats(struct mi_root
*cmd, void *param)</div>
<div>+{</div>
<div>+ struct mi_root *rpl_tree;</div>
<div>+ struct mi_node *rpl;</div>
<div>+ struct mi_node *arg;</div>
<div>+ stat_var *stat;</div>
<div>+ str val;</div>
<div> </div>
<div>+</div>
<div>+ if(stats_support()==0)</div>
<div>+ return init_mi_tree( 404, "Statistics Not
Found", 20);</div>
<div>+</div>
<div>+ if (cmd->node.kids==NULL)</div>
<div>+ return init_mi_tree( 400,
MI_MISSING_PARM_S,
MI_MISSING_PARM_LEN
);</div>
<div>+</div>
<div>+ rpl_tree = init_mi_tree( 200, MI_OK_S,
MI_OK_LEN);</div>
<div>+ if (rpl_tree==0)</div>
<div>+ return 0;</div>
<div>+ rpl = &rpl_tree->node;</div>
<div>+</div>
<div>+ for( arg=cmd->node.kids ; arg ;
arg=arg->next) {</div>
<div>+ if (arg->value.len==0)</div>
<div>+ continue;</div>
<div>+</div>
<div>+ val = arg->value;</div>
<div>+</div>
<div>+ if ( val.len==3 &&
memcmp(val.s,"all",3)==0) {</div>
<div>+ /* add all statistic variables */</div>
<div>+ /* use direct counters access for
that */</div>
<div>+
counter_iterate_grp_names(mi_add_all_grps_cbk2, rpl);</div>
<div>+ } else if ( val.len>1 &&
val.s[val.len-1]==':') {</div>
<div>+ /* add module statistics */</div>
<div>+ val.len--;</div>
<div>+ val.s[val.len]=0; /* zero term.
*/</div>
<div>+ /* use direct counters access for
that */</div>
<div>+ counter_iterate_grp_vars(val.s,
mi_add_grp_vars_cbk2, rpl);</div>
<div>+ val.s[val.len]=':' /* restore */;</div>
<div>+ } else {</div>
<div>+ /* reset & return only one
statistic */</div>
<div>+ stat = get_stat( &val );</div>
<div>+</div>
<div>+ if (stat==0)</div>
<div>+ continue;</div>
<div>+ if
(mi_reset_and_add_stat(rpl,stat)!=0)</div>
<div>+ goto error;</div>
<div>+ }</div>
<div>+ }</div>
<div>+</div>
<div>+ if (rpl->kids==0) {</div>
<div>+ free_mi_tree(rpl_tree);</div>
<div>+ return init_mi_tree( 404, "Statistics Not
Found", 20);</div>
<div>+ }</div>
<div>+</div>
<div>+ return rpl_tree;</div>
<div>+error:</div>
<div>+ free_mi_tree(rpl_tree);</div>
<div>+ return 0;</div>
<div>+}</div>
<div>+</div>
<div>+</div>
<div>static struct mi_root *mi_reset_stats(struct mi_root
*cmd, void *param)</div>
<div>{</div>
<div> struct mi_root *rpl_tree;</div>
<div> </div>
<div style="font-style: normal; display: inline; font-family:
'Calibri'; color: rgb(0, 0, 0); font-size: small;
font-weight: normal; text-decoration: none;">
<div style="font: 10pt tahoma;">
<div> </div>
<div style="background: none repeat scroll 0% 0% rgb(245,
245, 245);">
<div style=""><b>From:</b> <a moz-do-not-send="true"
title="miconda@gmail.com"
href="mailto:miconda@gmail.com">Daniel-Constantin
Mierla</a> </div>
<div><b>Sent:</b> Tuesday, March 29, 2011 11:59 AM</div>
<div><b>To:</b> <a moz-do-not-send="true"
title="paul@crocodile-rcs.com"
href="mailto:paul@crocodile-rcs.com">Paul Pankhurst</a>
</div>
<div><b>Subject:</b> Re: [sr-dev] Fw: 32bit vs 64bit
build problems</div>
</div>
</div>
<div> </div>
</div>
<div style="font-style: normal; display: inline; font-family:
'Calibri'; color: rgb(0, 0, 0); font-size: small;
font-weight: normal; text-decoration: none;">Hi Paul,<br>
<br>
the return of int instead of long is a bug and I will try to
fix asap.<br>
<br>
The new command to reset statistics is an addition and we
can add it whenever you want. You don't need to wait for
Peter, you can send the patch to sr-dev and will be added
into the master branch (devel version). Over the time, if
you plan to contribute more code and come with new patches I
can just grant you commit access to git, so you can commit
directly there, either on master branch or your own one and
then merge to master.<br>
<br>
Thanks,<br>
Daniel <br>
<br>
On 3/29/11 12:53 PM, Paul Pankhurst wrote:
<blockquote
cite="mid:F00CCAF878E84B9DA94264FF66D1E153@pjplaptop"
type="cite">
<div dir="ltr">
<div style="font-family: 'Calibri'; color: rgb(0, 0, 0);
font-size: 12pt;">
<div>Hi Daniel,</div>
<div> </div>
<div>Anything that calls get_stat_val is potentially a
problem – I did a ‘bodge’ fix by adding
get_stat_val_long function and calling that from
kex/core_stats.c instead of get_stat_val. I wasn’t
sure if modifying get_stat_val was going to break
something else that relied on the return NOT being a
long from this function!</div>
<div> </div>
<div>Incidentally I have also extended core_stats.c by
adding a clear_statistics mi command that takes the
same params as get_statistics, thus allowing users
to reset a group or all stats at the same time. My
intention is to submit this back to the
communits(possibly packaged with Peters presence
changes unless you’d prefer them separate)</div>
<div> </div>
<div>Paul</div>
<div style="font-style: normal; display: inline;
font-family: 'Calibri'; color: rgb(0, 0, 0);
font-size: small; font-weight: normal;
text-decoration: none;">
<div style="font: 10pt tahoma;">
<div> </div>
<div style="background: none repeat scroll 0% 0%
rgb(245, 245, 245);">
<div><b>From:</b> <a title="miconda@gmail.com"
href="mailto:miconda@gmail.com"
moz-do-not-send="true">Daniel-Constantin
Mierla</a> </div>
<div><b>Sent:</b> Tuesday, March 29, 2011 11:36
AM</div>
<div><b>To:</b> <a
title="sr-dev@lists.sip-router.org"
href="mailto:sr-dev@lists.sip-router.org"
moz-do-not-send="true">Development mailing
list of the sip-router project</a> </div>
<div><b>Cc:</b> <a
title="paul@crocodile-rcs.com"
href="mailto:paul@crocodile-rcs.com"
moz-do-not-send="true">Paul Pankhurst</a> </div>
<div><b>Subject:</b> Re: [sr-dev] Fw: 32bit vs
64bit build problems</div>
</div>
</div>
<div> </div>
</div>
<div style="font-style: normal; display: inline;
font-family: 'Calibri'; color: rgb(0, 0, 0);
font-size: small; font-weight: normal;
text-decoration: none;">Hi Paul,<br>
<br>
indeed, some of these stats are not consistent. I
will go through them. General idea is that the old
stats framework will be replaced by a new one
(present already in the code) that does not need any
kind of locking when updating the counters, thus is
faster.<br>
<br>
If you have specific examples of current stats that
go nuts in 64b, please report them here so I will
start with them then I will go through the rest of
sources.<br>
<br>
Thanks,<br>
Daniel<br>
<br>
On 3/29/11 12:04 PM, Paul Pankhurst wrote:
<blockquote
cite="mid:E7A3523988114F68AED3D320F711621F@pjplaptop"
type="cite">
<div dir="ltr">
<div style="font-family: 'Calibri'; color:
rgb(0, 0, 0); font-size: 12pt;">
<div style="font-style: normal; display:
inline; font-family: 'Calibri'; color:
rgb(0, 0, 0); font-size: small; font-weight:
normal; text-decoration: none;">
<div> </div>
</div>
<div style="font-style: normal; display:
inline; font-family: 'Calibri'; color:
rgb(0, 0, 0); font-size: small; font-weight:
normal; text-decoration: none;">
<div dir="ltr">
<div style="font-family: 'Calibri'; color:
rgb(0, 0, 0); font-size: 12pt;">
<div><font face="Times New Roman">I have
noticed that 'kamctl monitor'
displays corrupt statistics when
kamailio is built for a 64 bit
platform. <br>
<br>
Further investigation has revealed
that the reason is the underlying
datatype is a long, whilst some of
the wrapper functions (e.g.
get_stat_val) return unsigned int.
On a 32bit machine where a long and
int are both the same size it is not
a problem, but on a 64 bit machine
they are different and hence the
problem. <br>
<br>
Some code uses the wrapper function,
other does not, in the case of
mi_get_stats it uses both, so
depending on paramaters passed to
the MI fifo it may work or produce
garbage results. </font></div>
<div><br>
</div>
<div>Paul</div>
</div>
</div>
</div>
</div>
</div>
<pre wrap=""><fieldset class="mimeAttachmentHeader"></fieldset>
_______________________________________________
sr-dev mailing list
<a class="moz-txt-link-abbreviated" href="mailto:sr-dev@lists.sip-router.org" moz-do-not-send="true">sr-dev@lists.sip-router.org</a>
<a class="moz-txt-link-freetext" href="http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev" moz-do-not-send="true">http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev</a>
</pre>
</blockquote>
<br>
<pre class="moz-signature" cols="72">--
Daniel-Constantin Mierla
<a class="moz-txt-link-freetext" href="http://www.asipto.com" moz-do-not-send="true">http://www.asipto.com</a></pre>
</div>
</div>
</div>
</blockquote>
<br>
<pre class="moz-signature" cols="72">--
Daniel-Constantin Mierla
<a moz-do-not-send="true" class="moz-txt-link-freetext" href="http://www.asipto.com">http://www.asipto.com</a></pre>
</div>
</div>
</div>
<pre wrap="">
<fieldset class="mimeAttachmentHeader"></fieldset>
_______________________________________________
sr-dev mailing list
<a class="moz-txt-link-abbreviated" href="mailto:sr-dev@lists.sip-router.org">sr-dev@lists.sip-router.org</a>
<a class="moz-txt-link-freetext" href="http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev">http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev</a>
</pre>
</blockquote>
<br>
<pre class="moz-signature" cols="72">--
Daniel-Constantin Mierla
<a class="moz-txt-link-freetext" href="http://www.asipto.com">http://www.asipto.com</a></pre>
</body>
</html>