[Asterisk-code-review] taskprocessor.c: Add CLI commands to reset taskprocessor stats. (...asterisk[master])

George Joseph asteriskteam at digium.com
Wed Sep 25 07:04:49 CDT 2019


George Joseph has submitted this change and it was merged. ( https://gerrit.asterisk.org/c/asterisk/+/12941 )

Change subject: taskprocessor.c: Add CLI commands to reset taskprocessor stats.
......................................................................

taskprocessor.c: Add CLI commands to reset taskprocessor stats.

Added two new CLI commands to reset stats for taskprocessors. You can
reset stats for a single, specific taskprocessor ('core reset
taskprocessor <taskprocessor>'), or you can reset all taskprocessors
('core reset taskprocessors'). These commands will reset the counter for
the number of tasks processed as well as the max queue size.

Change-Id: Iaf17fc4ae29396ab0c6ac92408fc7bdc2f12362d
---
A doc/CHANGES-staging/taskprocessor-reset-stats.txt
M main/taskprocessor.c
2 files changed, 85 insertions(+), 0 deletions(-)

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



diff --git a/doc/CHANGES-staging/taskprocessor-reset-stats.txt b/doc/CHANGES-staging/taskprocessor-reset-stats.txt
new file mode 100644
index 0000000..b5ebb86
--- /dev/null
+++ b/doc/CHANGES-staging/taskprocessor-reset-stats.txt
@@ -0,0 +1,7 @@
+Subject: taskprocessor.c
+
+Added two new CLI commands to reset stats for taskprocessors. You can
+reset stats for a single, specific taskprocessor ('core reset
+taskprocessor <taskprocessor>'), or you can reset all taskprocessors
+('core reset taskprocessors'). These commands will reset the counter for
+the number of tasks processed as well as the max queue size.
diff --git a/main/taskprocessor.c b/main/taskprocessor.c
index df60236..39372dc 100644
--- a/main/taskprocessor.c
+++ b/main/taskprocessor.c
@@ -153,11 +153,15 @@
 static char *cli_tps_ping(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
 static char *cli_tps_report(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
 static char *cli_subsystem_alert_report(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
+static char *cli_tps_reset_stats(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
+static char *cli_tps_reset_stats_all(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
 
 static struct ast_cli_entry taskprocessor_clis[] = {
 	AST_CLI_DEFINE(cli_tps_ping, "Ping a named task processor"),
 	AST_CLI_DEFINE(cli_tps_report, "List instantiated task processors and statistics"),
 	AST_CLI_DEFINE(cli_subsystem_alert_report, "List task processor subsystems in alert"),
+	AST_CLI_DEFINE(cli_tps_reset_stats, "Reset a named task processor's stats"),
+	AST_CLI_DEFINE(cli_tps_reset_stats_all, "Reset all task processors' stats"),
 };
 
 struct default_taskprocessor_listener_pvt {
@@ -1254,3 +1258,77 @@
 	/* Append sequence number to end of user name. */
 	snprintf(buf + user_size, SEQ_STR_SIZE, "-%08x", ast_taskprocessor_seq_num());
 }
+
+static void tps_reset_stats(struct ast_taskprocessor *tps)
+{
+	ao2_lock(tps);
+	tps->stats._tasks_processed_count = 0;
+	tps->stats.max_qsize = 0;
+	ao2_unlock(tps);
+}
+
+static char *cli_tps_reset_stats(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+	const char *name;
+	struct ast_taskprocessor *tps;
+
+	switch (cmd) {
+	case CLI_INIT:
+		e->command = "core reset taskprocessor";
+		e->usage =
+			"Usage: core reset taskprocessor <taskprocessor>\n"
+			"    Resets stats for the specified taskprocessor\n";
+		return NULL;
+	case CLI_GENERATE:
+		return tps_taskprocessor_tab_complete(a);
+	}
+
+	if (a->argc != 4) {
+		return CLI_SHOWUSAGE;
+	}
+
+	name = a->argv[3];
+	if (!(tps = ast_taskprocessor_get(name, TPS_REF_IF_EXISTS))) {
+		ast_cli(a->fd, "\nReset failed: %s not found\n\n", name);
+		return CLI_SUCCESS;
+	}
+	ast_cli(a->fd, "\nResetting %s\n\n", name);
+
+	tps_reset_stats(tps);
+
+	ast_taskprocessor_unreference(tps);
+
+	return CLI_SUCCESS;
+}
+
+static char *cli_tps_reset_stats_all(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+	struct ast_taskprocessor *tps;
+	struct ao2_iterator iter;
+
+	switch (cmd) {
+	case CLI_INIT:
+		e->command = "core reset taskprocessors";
+		e->usage =
+			"Usage: core reset taskprocessors\n"
+			"    Resets stats for all taskprocessors\n";
+		return NULL;
+	case CLI_GENERATE:
+		return NULL;
+	}
+
+	if (a->argc != e->args) {
+		return CLI_SHOWUSAGE;
+	}
+
+	ast_cli(a->fd, "\nResetting stats for all taskprocessors\n\n");
+
+	iter = ao2_iterator_init(tps_singletons, 0);
+	while ((tps = ao2_iterator_next(&iter))) {
+		tps_reset_stats(tps);
+		ast_taskprocessor_unreference(tps);
+	}
+	ao2_iterator_destroy(&iter);
+
+	return CLI_SUCCESS;
+}

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/12941
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Change-Id: Iaf17fc4ae29396ab0c6ac92408fc7bdc2f12362d
Gerrit-Change-Number: 12941
Gerrit-PatchSet: 2
Gerrit-Owner: Benjamin Keith Ford <bford at digium.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Richard Mudgett <rmudgett 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/20190925/c19d1f69/attachment-0001.html>


More information about the asterisk-code-review mailing list