<p>Jaco Kroon has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/15942">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">func_lock: Add "locks show" cli command.<br><br>For example:<br><br>arthur*CLI> locks show<br>func_lock locks:<br>Name                                     Requesters Owner<br>uls-autoref                              0          (unlocked)<br>1 total locks listed.<br><br>Obviously other potentially useful stats could be added (eg, how many<br>times there was contention, how many times it failed etc ... but that<br>would require keeping the stats and I'm not convinced that's worth the<br>effort.  This was useful to troubleshoot some other issues so submitting<br>it.<br><br>Change-Id: Ib875e56feb49d523300aec5f36c635ed74843a9f<br>Signed-off-by: Jaco Kroon <jaco@uls.co.za><br>---<br>M funcs/func_lock.c<br>1 file changed, 37 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/42/15942/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/funcs/func_lock.c b/funcs/func_lock.c</span><br><span>index 0726407..fc99d49 100644</span><br><span>--- a/funcs/func_lock.c</span><br><span>+++ b/funcs/func_lock.c</span><br><span>@@ -42,6 +42,7 @@</span><br><span> #include "asterisk/linkedlists.h"</span><br><span> #include "asterisk/astobj2.h"</span><br><span> #include "asterisk/utils.h"</span><br><span style="color: hsl(120, 100%, 40%);">+#include "asterisk/cli.h"</span><br><span> </span><br><span> /*** DOCUMENTATION</span><br><span>      <function name="LOCK" language="en_US"></span><br><span>@@ -409,6 +410,37 @@</span><br><span>     return 0;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+static char *handle_cli_locks_show(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+   int c = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+    struct lock_frame* current;</span><br><span style="color: hsl(120, 100%, 40%);">+   switch (cmd) {</span><br><span style="color: hsl(120, 100%, 40%);">+        case CLI_INIT:</span><br><span style="color: hsl(120, 100%, 40%);">+                e->command = "locks show";</span><br><span style="color: hsl(120, 100%, 40%);">+               e->usage =</span><br><span style="color: hsl(120, 100%, 40%);">+                 "Usage: locks show\n"</span><br><span style="color: hsl(120, 100%, 40%);">+                       "       List all locks known to func_lock, along with their current status.\n";</span><br><span style="color: hsl(120, 100%, 40%);">+             return NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+  case CLI_GENERATE:</span><br><span style="color: hsl(120, 100%, 40%);">+            return NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+  }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   ast_cli(a->fd, "func_lock locks:\n");</span><br><span style="color: hsl(120, 100%, 40%);">+    ast_cli(a->fd, "%-40s Requesters Owner\n", "Name");</span><br><span style="color: hsl(120, 100%, 40%);">+    AST_LIST_LOCK(&locklist);</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_LIST_TRAVERSE(&locklist, current, entries) {</span><br><span style="color: hsl(120, 100%, 40%);">+          ast_mutex_lock(&current->mutex);</span><br><span style="color: hsl(120, 100%, 40%);">+               ast_cli(a->fd, "%-40s %-10d %s\n", current->name, current->requesters,</span><br><span style="color: hsl(120, 100%, 40%);">+                             current->owner ? ast_channel_name(current->owner) : "(unlocked)");</span><br><span style="color: hsl(120, 100%, 40%);">+            ast_mutex_unlock(&current->mutex);</span><br><span style="color: hsl(120, 100%, 40%);">+             c++;</span><br><span style="color: hsl(120, 100%, 40%);">+  }</span><br><span style="color: hsl(120, 100%, 40%);">+     AST_LIST_UNLOCK(&locklist);</span><br><span style="color: hsl(120, 100%, 40%);">+       ast_cli(a->fd, "%d total locks listed.\n", c);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> static struct ast_custom_function lock_function = {</span><br><span>        .name = "LOCK",</span><br><span>    .read = lock_read,</span><br><span>@@ -427,6 +459,8 @@</span><br><span>     .read_max = 2,</span><br><span> };</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+static struct ast_cli_entry cli_locks_show = AST_CLI_DEFINE(handle_cli_locks_show, "List func_lock locks.");</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> static int unload_module(void)</span><br><span> {</span><br><span>    struct lock_frame *current;</span><br><span>@@ -439,6 +473,8 @@</span><br><span>    ast_custom_function_unregister(&lock_function);</span><br><span>  ast_custom_function_unregister(&trylock_function);</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+    ast_cli_unregister(&cli_locks_show);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>   AST_LIST_LOCK(&locklist);</span><br><span>        AST_LIST_TRAVERSE(&locklist, current, entries) {</span><br><span>                 ast_mutex_lock(&current->mutex);</span><br><span>@@ -470,6 +506,7 @@</span><br><span>        int res = ast_custom_function_register_escalating(&lock_function, AST_CFE_READ);</span><br><span>         res |= ast_custom_function_register_escalating(&trylock_function, AST_CFE_READ);</span><br><span>         res |= ast_custom_function_register_escalating(&unlock_function, AST_CFE_READ);</span><br><span style="color: hsl(120, 100%, 40%);">+   res |= ast_cli_register(&cli_locks_show);</span><br><span> </span><br><span>    return res;</span><br><span> }</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/15942">change 15942</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/15942"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: Ib875e56feb49d523300aec5f36c635ed74843a9f </div>
<div style="display:none"> Gerrit-Change-Number: 15942 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Jaco Kroon <jaco@uls.co.za> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>