[Asterisk-code-review] taskprocessor.c: Added "like" support to 'core show taskprocessors' (...asterisk[17])
George Joseph
asteriskteam at digium.com
Fri Sep 27 08:56:30 CDT 2019
George Joseph has submitted this change and it was merged. ( https://gerrit.asterisk.org/c/asterisk/+/12962 )
Change subject: taskprocessor.c: Added "like" support to 'core show taskprocessors'
......................................................................
taskprocessor.c: Added "like" support to 'core show taskprocessors'
Added "like" support for 'core show taskprocessors'. Now you
can specify a specific set of taskprocessors (or just one) by
adding the keyword "like" to the above command, followed by
your search criteria.
Change-Id: I021e740201e9ba487204b5451e46feb0e3222464
---
A doc/CHANGES-staging/taskprocessor-like-support.txt
M main/taskprocessor.c
2 files changed, 99 insertions(+), 45 deletions(-)
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
diff --git a/doc/CHANGES-staging/taskprocessor-like-support.txt b/doc/CHANGES-staging/taskprocessor-like-support.txt
new file mode 100644
index 0000000..8f61d39
--- /dev/null
+++ b/doc/CHANGES-staging/taskprocessor-like-support.txt
@@ -0,0 +1,6 @@
+Subject: taskprocessor.c
+
+Added "like" support for 'core show taskprocessors'. Now you
+can specify a specific set of taskprocessors (or just one) by
+adding the keyword "like" to the above command, followed by
+your search criteria.
diff --git a/main/taskprocessor.c b/main/taskprocessor.c
index 39372dc..47d75d3 100644
--- a/main/taskprocessor.c
+++ b/main/taskprocessor.c
@@ -371,17 +371,17 @@
return NULL;
}
-/* taskprocessor tab completion */
+/* Taskprocessor tab completion.
+ *
+ * The caller of this function is responsible for argument
+ * position checks prior to calling.
+ */
static char *tps_taskprocessor_tab_complete(struct ast_cli_args *a)
{
int tklen;
struct ast_taskprocessor *p;
struct ao2_iterator i;
- if (a->pos != 3) {
- return NULL;
- }
-
tklen = strlen(a->word);
i = ao2_iterator_init(tps_singletons, 0);
while ((p = ao2_iterator_next(&i))) {
@@ -424,7 +424,11 @@
" Displays the time required for a task to be processed\n";
return NULL;
case CLI_GENERATE:
- return tps_taskprocessor_tab_complete(a);
+ if (a->pos == 3) {
+ return tps_taskprocessor_tab_complete(a);
+ } else {
+ return NULL;
+ }
}
if (a->argc != 4)
@@ -503,58 +507,102 @@
return cmp;
}
-static char *cli_tps_report(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
-{
- char name[256];
- int tcount;
- unsigned long qsize;
- unsigned long maxqsize;
- unsigned long processed;
- struct ao2_container *sorted_tps;
- struct ast_taskprocessor *tps;
- struct ao2_iterator iter;
#define FMT_HEADERS "%-70s %10s %10s %10s %10s %10s\n"
#define FMT_FIELDS "%-70s %10lu %10lu %10lu %10lu %10lu\n"
- switch (cmd) {
- case CLI_INIT:
- e->command = "core show taskprocessors";
- e->usage =
- "Usage: core show taskprocessors\n"
- " Shows a list of instantiated task processors and their statistics\n";
- return NULL;
- case CLI_GENERATE:
- return NULL;
- }
+/*!
+ * \internal
+ * \brief Print taskprocessor information to CLI.
+ * \since 13.30.0
+ *
+ * \param fd the file descriptor
+ * \param tps the taskprocessor
+ */
+static void tps_report_taskprocessor_list_helper(int fd, struct ast_taskprocessor *tps)
+{
+ ast_cli(fd, FMT_FIELDS, tps->name, tps->stats._tasks_processed_count,
+ tps->tps_queue_size, tps->stats.max_qsize, tps->tps_queue_low,
+ tps->tps_queue_high);
+}
- if (a->argc != e->args) {
- return CLI_SHOWUSAGE;
- }
+/*!
+ * \internal
+ * \brief Prints an optionally narrowed down list of taskprocessors to the CLI.
+ * \since 13.30.0
+ *
+ * \param fd the file descriptor
+ * \param like the string we are matching on
+ *
+ * \retval number of taskprocessors on success
+ * \retval 0 otherwise
+ */
+static int tps_report_taskprocessor_list(int fd, const char *like)
+{
+ int tps_count = 0;
+ int word_len;
+ struct ao2_container *sorted_tps;
+ struct ast_taskprocessor *tps;
+ struct ao2_iterator iter;
sorted_tps = ao2_container_alloc_rbtree(AO2_ALLOC_OPT_LOCK_NOLOCK, 0, tps_sort_cb,
NULL);
if (!sorted_tps
|| ao2_container_dup(sorted_tps, tps_singletons, 0)) {
+ ast_debug(1, "Failed to retrieve sorted taskprocessors\n");
ao2_cleanup(sorted_tps);
- return CLI_FAILURE;
+ return 0;
+ }
+
+ word_len = strlen(like);
+ iter = ao2_iterator_init(sorted_tps, AO2_ITERATOR_UNLINK);
+ while ((tps = ao2_iterator_next(&iter))) {
+ if (like) {
+ if (!strncasecmp(like, tps->name, word_len)) {
+ tps_report_taskprocessor_list_helper(fd, tps);
+ tps_count++;
+ }
+ } else {
+ tps_report_taskprocessor_list_helper(fd, tps);
+ tps_count++;
+ }
+ ast_taskprocessor_unreference(tps);
+ }
+ ao2_iterator_destroy(&iter);
+ ao2_ref(sorted_tps, -1);
+
+ return tps_count;
+}
+
+static char *cli_tps_report(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+ const char *like;
+
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "core show taskprocessors [like]";
+ e->usage =
+ "Usage: core show taskprocessors [like keyword]\n"
+ " Shows a list of instantiated task processors and their statistics\n";
+ return NULL;
+ case CLI_GENERATE:
+ if (a->pos == e->args) {
+ return tps_taskprocessor_tab_complete(a);
+ } else {
+ return NULL;
+ }
+ }
+
+ if (a->argc == e->args - 1) {
+ like = "";
+ } else if (a->argc == e->args + 1 && !strcasecmp(a->argv[e->args-1], "like")) {
+ like = a->argv[e->args];
+ } else {
+ return CLI_SHOWUSAGE;
}
ast_cli(a->fd, "\n" FMT_HEADERS, "Processor", "Processed", "In Queue", "Max Depth", "Low water", "High water");
- tcount = 0;
- iter = ao2_iterator_init(sorted_tps, AO2_ITERATOR_UNLINK);
- while ((tps = ao2_iterator_next(&iter))) {
- ast_copy_string(name, tps->name, sizeof(name));
- qsize = tps->tps_queue_size;
- maxqsize = tps->stats.max_qsize;
- processed = tps->stats._tasks_processed_count;
- ast_cli(a->fd, FMT_FIELDS, name, processed, qsize, maxqsize,
- tps->tps_queue_low, tps->tps_queue_high);
- ast_taskprocessor_unreference(tps);
- ++tcount;
- }
- ao2_iterator_destroy(&iter);
- ast_cli(a->fd, "\n%d taskprocessors\n\n", tcount);
- ao2_ref(sorted_tps, -1);
+ ast_cli(a->fd, "\n%d taskprocessors\n\n", tps_report_taskprocessor_list(a->fd, like));
+
return CLI_SUCCESS;
}
--
To view, visit https://gerrit.asterisk.org/c/asterisk/+/12962
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: 17
Gerrit-Change-Id: I021e740201e9ba487204b5451e46feb0e3222464
Gerrit-Change-Number: 12962
Gerrit-PatchSet: 3
Gerrit-Owner: Benjamin Keith Ford <bford at digium.com>
Gerrit-Reviewer: Benjamin Keith Ford <bford at digium.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Sean Bright <sean.bright at gmail.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20190927/eda8123c/attachment-0001.html>
More information about the asterisk-code-review
mailing list