<p>Benjamin Keith Ford has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/12960">View Change</a></p><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, 149 insertions(+), 41 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/60/12960/1</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 270ce74..b9b58cf 100644</span><br><span>--- a/main/taskprocessor.c</span><br><span>+++ b/main/taskprocessor.c</span><br><span>@@ -501,58 +501,160 @@</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(120, 100%, 40%);">+/*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \internal</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Create and return a sorted taskprocessor ao2 container.</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%);">+ * \note The container will need to be unref'd by the caller.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval sorted container on success</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval NULL on failure</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+static struct ao2_container *get_sorted_taskprocessors_list(void)</span><br><span> {</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> 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 style="color: hsl(0, 100%, 40%);">-#define FMT_HEADERS "%-70s %10s %10s %10s %10s %10s\n"</span><br><span style="color: hsl(0, 100%, 40%);">-#define FMT_FIELDS "%-70s %10lu %10lu %10lu %10lu %10lu\n"</span><br><span style="color: hsl(0, 100%, 40%);">-</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(0, 100%, 40%);">-</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> </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 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%);">+ return sorted_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%);">+/*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \internal</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Tab completion for taskprocessors.</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 word the string to tab complete on</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param state the current state of the word for tab completion</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval match on success</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval NULL on failure</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+static char *tps_report_generate_helper(const char *word, int state)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ int which = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ int wordlen = strlen(word);</span><br><span style="color: hsl(120, 100%, 40%);">+ char *ret = NULL;</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 style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ sorted_tps = get_sorted_taskprocessors_list();</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!sorted_tps) {</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%);">+ 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 (!strncasecmp(word, tps->name, wordlen) && ++which > state) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ret = ast_strdup(tps->name);</span><br><span style="color: hsl(120, 100%, 40%);">+ break;</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%);">+ 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 ret;</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%);">+#define FMT_HEADERS "%-70s %10s %10s %10s %10s %10s\n"</span><br><span style="color: hsl(120, 100%, 40%);">+#define FMT_FIELDS "%-70s %10lu %10lu %10lu %10lu %10lu\n"</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%);">+ * \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 style="color: hsl(120, 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%);">+ 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 style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ sorted_tps = get_sorted_taskprocessors_list();</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!sorted_tps) {</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%);">+ 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, strlen(like))) {</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_report_generate_helper(a->word, a->n);</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/+/12960">change 12960</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/+/12960"/><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: I021e740201e9ba487204b5451e46feb0e3222464 </div>
<div style="display:none"> Gerrit-Change-Number: 12960 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Benjamin Keith Ford <bford@digium.com> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>