<p>George Joseph <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/12962">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Sean Bright: Looks good to me, but someone else must approve
Joshua Colp: 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: Added "like" support to 'core show taskprocessors'<br><br>Added "like" support for 'core show taskprocessors'. Now you<br>can specify a specific set of taskprocessors (or just one) by<br>adding the keyword "like" to the above command, followed by<br>your search criteria.<br><br>Change-Id: I021e740201e9ba487204b5451e46feb0e3222464<br>---<br>A doc/CHANGES-staging/taskprocessor-like-support.txt<br>M main/taskprocessor.c<br>2 files changed, 99 insertions(+), 45 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/doc/CHANGES-staging/taskprocessor-like-support.txt b/doc/CHANGES-staging/taskprocessor-like-support.txt</span><br><span>new file mode 100644</span><br><span>index 0000000..8f61d39</span><br><span>--- /dev/null</span><br><span>+++ b/doc/CHANGES-staging/taskprocessor-like-support.txt</span><br><span>@@ -0,0 +1,6 @@</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 "like" support for 'core show taskprocessors'. Now you</span><br><span style="color: hsl(120, 100%, 40%);">+can specify a specific set of taskprocessors (or just one) by</span><br><span style="color: hsl(120, 100%, 40%);">+adding the keyword "like" to the above command, followed by</span><br><span style="color: hsl(120, 100%, 40%);">+your search criteria.</span><br><span>diff --git a/main/taskprocessor.c b/main/taskprocessor.c</span><br><span>index 39372dc..47d75d3 100644</span><br><span>--- a/main/taskprocessor.c</span><br><span>+++ b/main/taskprocessor.c</span><br><span>@@ -371,17 +371,17 @@</span><br><span> return NULL;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-/* taskprocessor tab completion */</span><br><span style="color: hsl(120, 100%, 40%);">+/* Taskprocessor tab completion.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * The caller of this function is responsible for argument</span><br><span style="color: hsl(120, 100%, 40%);">+ * position checks prior to calling.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span> static char *tps_taskprocessor_tab_complete(struct ast_cli_args *a)</span><br><span> {</span><br><span> int tklen;</span><br><span> struct ast_taskprocessor *p;</span><br><span> struct ao2_iterator i;</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- if (a->pos != 3) {</span><br><span style="color: hsl(0, 100%, 40%);">- return NULL;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> tklen = strlen(a->word);</span><br><span> i = ao2_iterator_init(tps_singletons, 0);</span><br><span> while ((p = ao2_iterator_next(&i))) {</span><br><span>@@ -424,7 +424,11 @@</span><br><span> " Displays the time required for a task to be processed\n";</span><br><span> return NULL;</span><br><span> case CLI_GENERATE:</span><br><span style="color: hsl(0, 100%, 40%);">- return tps_taskprocessor_tab_complete(a);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (a->pos == 3) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return tps_taskprocessor_tab_complete(a);</span><br><span style="color: hsl(120, 100%, 40%);">+ } else {</span><br><span style="color: hsl(120, 100%, 40%);">+ return NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> }</span><br><span> </span><br><span> if (a->argc != 4)</span><br><span>@@ -503,58 +507,102 @@</span><br><span> return cmp;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-static char *cli_tps_report(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)</span><br><span style="color: hsl(0, 100%, 40%);">-{</span><br><span style="color: hsl(0, 100%, 40%);">- char name[256];</span><br><span style="color: hsl(0, 100%, 40%);">- int tcount;</span><br><span style="color: hsl(0, 100%, 40%);">- unsigned long qsize;</span><br><span style="color: hsl(0, 100%, 40%);">- unsigned long maxqsize;</span><br><span style="color: hsl(0, 100%, 40%);">- unsigned long processed;</span><br><span style="color: hsl(0, 100%, 40%);">- struct ao2_container *sorted_tps;</span><br><span style="color: hsl(0, 100%, 40%);">- struct ast_taskprocessor *tps;</span><br><span style="color: hsl(0, 100%, 40%);">- struct ao2_iterator iter;</span><br><span> #define FMT_HEADERS "%-70s %10s %10s %10s %10s %10s\n"</span><br><span> #define FMT_FIELDS "%-70s %10lu %10lu %10lu %10lu %10lu\n"</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- switch (cmd) {</span><br><span style="color: hsl(0, 100%, 40%);">- case CLI_INIT:</span><br><span style="color: hsl(0, 100%, 40%);">- e->command = "core show taskprocessors";</span><br><span style="color: hsl(0, 100%, 40%);">- e->usage =</span><br><span style="color: hsl(0, 100%, 40%);">- "Usage: core show taskprocessors\n"</span><br><span style="color: hsl(0, 100%, 40%);">- " Shows a list of instantiated task processors and their statistics\n";</span><br><span style="color: hsl(0, 100%, 40%);">- return NULL;</span><br><span style="color: hsl(0, 100%, 40%);">- case CLI_GENERATE:</span><br><span style="color: hsl(0, 100%, 40%);">- return NULL;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \internal</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Print taskprocessor information to CLI.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \since 13.30.0</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param fd the file descriptor</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param tps the taskprocessor</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+static void tps_report_taskprocessor_list_helper(int fd, struct ast_taskprocessor *tps)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_cli(fd, FMT_FIELDS, tps->name, tps->stats._tasks_processed_count,</span><br><span style="color: hsl(120, 100%, 40%);">+ tps->tps_queue_size, tps->stats.max_qsize, tps->tps_queue_low,</span><br><span style="color: hsl(120, 100%, 40%);">+ tps->tps_queue_high);</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- if (a->argc != e->args) {</span><br><span style="color: hsl(0, 100%, 40%);">- return CLI_SHOWUSAGE;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \internal</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Prints an optionally narrowed down list of taskprocessors to the CLI.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \since 13.30.0</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param fd the file descriptor</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param like the string we are matching on</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval number of taskprocessors on success</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval 0 otherwise</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+static int tps_report_taskprocessor_list(int fd, const char *like)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ int tps_count = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ int word_len;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ao2_container *sorted_tps;</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> </span><br><span> sorted_tps = ao2_container_alloc_rbtree(AO2_ALLOC_OPT_LOCK_NOLOCK, 0, tps_sort_cb,</span><br><span> NULL);</span><br><span> if (!sorted_tps</span><br><span> || ao2_container_dup(sorted_tps, tps_singletons, 0)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_debug(1, "Failed to retrieve sorted taskprocessors\n");</span><br><span> ao2_cleanup(sorted_tps);</span><br><span style="color: hsl(0, 100%, 40%);">- return CLI_FAILURE;</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 style="color: hsl(120, 100%, 40%);">+ word_len = strlen(like);</span><br><span style="color: hsl(120, 100%, 40%);">+ iter = ao2_iterator_init(sorted_tps, AO2_ITERATOR_UNLINK);</span><br><span style="color: hsl(120, 100%, 40%);">+ while ((tps = ao2_iterator_next(&iter))) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (like) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!strncasecmp(like, tps->name, word_len)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ tps_report_taskprocessor_list_helper(fd, tps);</span><br><span style="color: hsl(120, 100%, 40%);">+ tps_count++;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ } else {</span><br><span style="color: hsl(120, 100%, 40%);">+ tps_report_taskprocessor_list_helper(fd, tps);</span><br><span style="color: hsl(120, 100%, 40%);">+ tps_count++;</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%);">+ ao2_iterator_destroy(&iter);</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_ref(sorted_tps, -1);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ return tps_count;</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_report(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 *like;</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 show taskprocessors [like]";</span><br><span style="color: hsl(120, 100%, 40%);">+ e->usage =</span><br><span style="color: hsl(120, 100%, 40%);">+ "Usage: core show taskprocessors [like keyword]\n"</span><br><span style="color: hsl(120, 100%, 40%);">+ " Shows a list of instantiated task processors and their statistics\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%);">+ if (a->pos == e->args) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return tps_taskprocessor_tab_complete(a);</span><br><span style="color: hsl(120, 100%, 40%);">+ } else {</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%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (a->argc == e->args - 1) {</span><br><span style="color: hsl(120, 100%, 40%);">+ like = "";</span><br><span style="color: hsl(120, 100%, 40%);">+ } else if (a->argc == e->args + 1 && !strcasecmp(a->argv[e->args-1], "like")) {</span><br><span style="color: hsl(120, 100%, 40%);">+ like = a->argv[e->args];</span><br><span style="color: hsl(120, 100%, 40%);">+ } else {</span><br><span style="color: hsl(120, 100%, 40%);">+ return CLI_SHOWUSAGE;</span><br><span> }</span><br><span> </span><br><span> ast_cli(a->fd, "\n" FMT_HEADERS, "Processor", "Processed", "In Queue", "Max Depth", "Low water", "High water");</span><br><span style="color: hsl(0, 100%, 40%);">- tcount = 0;</span><br><span style="color: hsl(0, 100%, 40%);">- iter = ao2_iterator_init(sorted_tps, AO2_ITERATOR_UNLINK);</span><br><span style="color: hsl(0, 100%, 40%);">- while ((tps = ao2_iterator_next(&iter))) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_copy_string(name, tps->name, sizeof(name));</span><br><span style="color: hsl(0, 100%, 40%);">- qsize = tps->tps_queue_size;</span><br><span style="color: hsl(0, 100%, 40%);">- maxqsize = tps->stats.max_qsize;</span><br><span style="color: hsl(0, 100%, 40%);">- processed = tps->stats._tasks_processed_count;</span><br><span style="color: hsl(0, 100%, 40%);">- ast_cli(a->fd, FMT_FIELDS, name, processed, qsize, maxqsize,</span><br><span style="color: hsl(0, 100%, 40%);">- tps->tps_queue_low, tps->tps_queue_high);</span><br><span style="color: hsl(0, 100%, 40%);">- ast_taskprocessor_unreference(tps);</span><br><span style="color: hsl(0, 100%, 40%);">- ++tcount;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- ao2_iterator_destroy(&iter);</span><br><span style="color: hsl(0, 100%, 40%);">- ast_cli(a->fd, "\n%d taskprocessors\n\n", tcount);</span><br><span style="color: hsl(0, 100%, 40%);">- ao2_ref(sorted_tps, -1);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_cli(a->fd, "\n%d taskprocessors\n\n", tps_report_taskprocessor_list(a->fd, like));</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> return CLI_SUCCESS;</span><br><span> }</span><br><span> </span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/12962">change 12962</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/+/12962"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 17 </div>
<div style="display:none"> Gerrit-Change-Id: I021e740201e9ba487204b5451e46feb0e3222464 </div>
<div style="display:none"> Gerrit-Change-Number: 12962 </div>
<div style="display:none"> Gerrit-PatchSet: 3 </div>
<div style="display:none"> Gerrit-Owner: Benjamin Keith Ford <bford@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: 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: Joshua Colp <jcolp@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Sean Bright <sean.bright@gmail.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>