<p>George Joseph <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/12938">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  Richard Mudgett: Looks good to me, but someone else must approve
  Sean Bright: Looks good to me, but someone else must approve
  George Joseph: Looks good to me, approved; Approved for Submit

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">taskprocessor.c: Add CLI commands to reset taskprocessor stats.<br><br>Added two new CLI commands to reset stats for taskprocessors. You can<br>reset stats for a single, specific taskprocessor ('core reset<br>taskprocessor <taskprocessor>'), or you can reset all taskprocessors<br>('core reset taskprocessors'). These commands will reset the counter for<br>the number of tasks processed as well as the max queue size.<br><br>Change-Id: Iaf17fc4ae29396ab0c6ac92408fc7bdc2f12362d<br>---<br>A doc/CHANGES-staging/taskprocessor-reset-stats.txt<br>M main/taskprocessor.c<br>2 files changed, 85 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/doc/CHANGES-staging/taskprocessor-reset-stats.txt b/doc/CHANGES-staging/taskprocessor-reset-stats.txt</span><br><span>new file mode 100644</span><br><span>index 0000000..b5ebb86</span><br><span>--- /dev/null</span><br><span>+++ b/doc/CHANGES-staging/taskprocessor-reset-stats.txt</span><br><span>@@ -0,0 +1,7 @@</span><br><span style="color: hsl(120, 100%, 40%);">+Subject: taskprocessor.c</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+Added two new CLI commands to reset stats for taskprocessors. You can</span><br><span style="color: hsl(120, 100%, 40%);">+reset stats for a single, specific taskprocessor ('core reset</span><br><span style="color: hsl(120, 100%, 40%);">+taskprocessor <taskprocessor>'), or you can reset all taskprocessors</span><br><span style="color: hsl(120, 100%, 40%);">+('core reset taskprocessors'). These commands will reset the counter for</span><br><span style="color: hsl(120, 100%, 40%);">+the number of tasks processed as well as the max queue size.</span><br><span>diff --git a/main/taskprocessor.c b/main/taskprocessor.c</span><br><span>index 270ce74..1b8c4a4 100644</span><br><span>--- a/main/taskprocessor.c</span><br><span>+++ b/main/taskprocessor.c</span><br><span>@@ -155,11 +155,15 @@</span><br><span> static char *cli_tps_ping(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);</span><br><span> static char *cli_tps_report(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);</span><br><span> static char *cli_subsystem_alert_report(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);</span><br><span style="color: hsl(120, 100%, 40%);">+static char *cli_tps_reset_stats(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);</span><br><span style="color: hsl(120, 100%, 40%);">+static char *cli_tps_reset_stats_all(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);</span><br><span> </span><br><span> static struct ast_cli_entry taskprocessor_clis[] = {</span><br><span>      AST_CLI_DEFINE(cli_tps_ping, "Ping a named task processor"),</span><br><span>       AST_CLI_DEFINE(cli_tps_report, "List instantiated task processors and statistics"),</span><br><span>        AST_CLI_DEFINE(cli_subsystem_alert_report, "List task processor subsystems in alert"),</span><br><span style="color: hsl(120, 100%, 40%);">+      AST_CLI_DEFINE(cli_tps_reset_stats, "Reset a named task processor's stats"),</span><br><span style="color: hsl(120, 100%, 40%);">+    AST_CLI_DEFINE(cli_tps_reset_stats_all, "Reset all task processors' stats"),</span><br><span> };</span><br><span> </span><br><span> struct default_taskprocessor_listener_pvt {</span><br><span>@@ -1256,3 +1260,77 @@</span><br><span>         /* Append sequence number to end of user name. */</span><br><span>    snprintf(buf + user_size, SEQ_STR_SIZE, "-%08x", ast_taskprocessor_seq_num());</span><br><span> }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static void tps_reset_stats(struct ast_taskprocessor *tps)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+        ao2_lock(tps);</span><br><span style="color: hsl(120, 100%, 40%);">+        tps->stats._tasks_processed_count = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+     tps->stats.max_qsize = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+  ao2_unlock(tps);</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%);">+static char *cli_tps_reset_stats(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%);">+  const char *name;</span><br><span style="color: hsl(120, 100%, 40%);">+     struct ast_taskprocessor *tps;</span><br><span style="color: hsl(120, 100%, 40%);">+</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 = "core reset taskprocessor";</span><br><span style="color: hsl(120, 100%, 40%);">+         e->usage =</span><br><span style="color: hsl(120, 100%, 40%);">+                 "Usage: core reset taskprocessor <taskprocessor>\n"</span><br><span style="color: hsl(120, 100%, 40%);">+                   "    Resets stats for the specified taskprocessor\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 tps_taskprocessor_tab_complete(a);</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%);">+   if (a->argc != 4) {</span><br><span style="color: hsl(120, 100%, 40%);">+                return CLI_SHOWUSAGE;</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%);">+   name = a->argv[3];</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!(tps = ast_taskprocessor_get(name, TPS_REF_IF_EXISTS))) {</span><br><span style="color: hsl(120, 100%, 40%);">+                ast_cli(a->fd, "\nReset failed: %s not found\n\n", name);</span><br><span style="color: hsl(120, 100%, 40%);">+                return CLI_SUCCESS;</span><br><span style="color: hsl(120, 100%, 40%);">+   }</span><br><span style="color: hsl(120, 100%, 40%);">+     ast_cli(a->fd, "\nResetting %s\n\n", name);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    tps_reset_stats(tps);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+       ast_taskprocessor_unreference(tps);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ return CLI_SUCCESS;</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%);">+static char *cli_tps_reset_stats_all(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%);">+   struct ast_taskprocessor *tps;</span><br><span style="color: hsl(120, 100%, 40%);">+        struct ao2_iterator iter;</span><br><span style="color: hsl(120, 100%, 40%);">+</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 = "core reset taskprocessors";</span><br><span style="color: hsl(120, 100%, 40%);">+                e->usage =</span><br><span style="color: hsl(120, 100%, 40%);">+                 "Usage: core reset taskprocessors\n"</span><br><span style="color: hsl(120, 100%, 40%);">+                        "    Resets stats for all taskprocessors\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%);">+   if (a->argc != e->args) {</span><br><span style="color: hsl(120, 100%, 40%);">+               return CLI_SHOWUSAGE;</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, "\nResetting stats for all taskprocessors\n\n");</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+        iter = ao2_iterator_init(tps_singletons, 0);</span><br><span style="color: hsl(120, 100%, 40%);">+  while ((tps = ao2_iterator_next(&iter))) {</span><br><span style="color: hsl(120, 100%, 40%);">+                tps_reset_stats(tps);</span><br><span style="color: hsl(120, 100%, 40%);">+         ast_taskprocessor_unreference(tps);</span><br><span style="color: hsl(120, 100%, 40%);">+   }</span><br><span style="color: hsl(120, 100%, 40%);">+     ao2_iterator_destroy(&iter);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    return CLI_SUCCESS;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/12938">change 12938</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/+/12938"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 13 </div>
<div style="display:none"> Gerrit-Change-Id: Iaf17fc4ae29396ab0c6ac92408fc7bdc2f12362d </div>
<div style="display:none"> Gerrit-Change-Number: 12938 </div>
<div style="display:none"> Gerrit-PatchSet: 2 </div>
<div style="display:none"> Gerrit-Owner: Benjamin Keith Ford <bford@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Richard Mudgett <rmudgett@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Sean Bright <sean.bright@gmail.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>