[Asterisk-code-review] stasis: Store subscriber uniqueids with topic statistics. (asterisk[13])

Joshua C. Colp asteriskteam at digium.com
Thu Feb 21 10:17:34 CST 2019


Joshua C. Colp has submitted this change and it was merged. ( https://gerrit.asterisk.org/11017 )

Change subject: stasis: Store subscriber uniqueids with topic statistics.
......................................................................

stasis: Store subscriber uniqueids with topic statistics.

This change provides an easier mechanism to determine which
subscribers are subscribed to a topic. Using this you can
inspect the specific subscribers for further details.

Change-Id: I8deea21703cd5c5357b85593b46c3eaf24e18c0c
---
M main/stasis.c
1 file changed, 29 insertions(+), 6 deletions(-)

Approvals:
  Kevin Harwell: Looks good to me, but someone else must approve
  George Joseph: Looks good to me, approved
  Joshua C. Colp: Approved for Submit



diff --git a/main/stasis.c b/main/stasis.c
index 5835a5a..397e501 100644
--- a/main/stasis.c
+++ b/main/stasis.c
@@ -349,8 +349,8 @@
 	int messages_not_dispatched;
 	/*! \brief The number of messages that were dispatched to at least 1 subscriber */
 	int messages_dispatched;
-	/*! \brief The number of subscribers to this topic */
-	int subscriber_count;
+	/*! \brief The ids of the subscribers to this topic */
+	struct ao2_container *subscribers;
 	/*! \brief Name of the topic */
 	char name[0];
 };
@@ -407,15 +407,28 @@
 }
 
 #ifdef AST_DEVMODE
+static void topic_statistics_destroy(void *obj)
+{
+	struct stasis_topic_statistics *statistics = obj;
+
+	ao2_cleanup(statistics->subscribers);
+}
+
 static struct stasis_topic_statistics *stasis_topic_statistics_create(const char *name)
 {
 	struct stasis_topic_statistics *statistics;
 
-	statistics = ao2_alloc(sizeof(*statistics) + strlen(name) + 1, NULL);
+	statistics = ao2_alloc(sizeof(*statistics) + strlen(name) + 1, topic_statistics_destroy);
 	if (!statistics) {
 		return NULL;
 	}
 
+	statistics->subscribers = ast_str_container_alloc(1);
+	if (!statistics->subscribers) {
+		ao2_ref(statistics, -1);
+		return NULL;
+	}
+
 	strcpy(statistics->name, name); /* SAFE */
 	ao2_link(topic_statistics, statistics);
 
@@ -1000,7 +1013,7 @@
 	}
 
 #ifdef AST_DEVMODE
-	topic->statistics->subscriber_count += 1;
+	ast_str_container_add(topic->statistics->subscribers, stasis_subscription_uniqueid(sub));
 #endif
 
 	ao2_unlock(topic);
@@ -1023,7 +1036,7 @@
 
 #ifdef AST_DEVMODE
 	if (!res) {
-		topic->statistics->subscriber_count -= 1;
+		ast_str_container_remove(topic->statistics->subscribers, stasis_subscription_uniqueid(sub));
 	}
 #endif
 
@@ -2294,6 +2307,8 @@
 static char *statistics_show_topic(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
 	struct stasis_topic_statistics *statistics;
+	struct ao2_iterator i;
+	char *uniqueid;
 
 	switch (cmd) {
 	case CLI_INIT:
@@ -2325,7 +2340,15 @@
 	ast_cli(a->fd, "Number of messages that went to at least one subscriber: %d\n", statistics->messages_dispatched);
 	ast_cli(a->fd, "Lowest amount of time (in milliseconds) spent dispatching message: %ld\n", statistics->lowest_time_dispatched);
 	ast_cli(a->fd, "Highest amount of time (in milliseconds) spent dispatching messages: %ld\n", statistics->highest_time_dispatched);
-	ast_cli(a->fd, "Number of subscribers: %d\n", statistics->subscriber_count);
+	ast_cli(a->fd, "Number of subscribers: %d\n", ao2_container_count(statistics->subscribers));
+
+	ast_cli(a->fd, "Subscribers:\n");
+	i = ao2_iterator_init(statistics->subscribers, 0);
+	while ((uniqueid = ao2_iterator_next(&i))) {
+		ast_cli(a->fd, "\t%s\n", uniqueid);
+		ao2_ref(uniqueid, -1);
+	}
+	ao2_iterator_destroy(&i);
 
 	ao2_ref(statistics, -1);
 

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

Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-MessageType: merged
Gerrit-Change-Id: I8deea21703cd5c5357b85593b46c3eaf24e18c0c
Gerrit-Change-Number: 11017
Gerrit-PatchSet: 1
Gerrit-Owner: Joshua C. Colp <jcolp at digium.com>
Gerrit-Reviewer: Friendly Automation (1000185)
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Joshua C. Colp <jcolp at digium.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20190221/1d651158/attachment-0001.html>


More information about the asterisk-code-review mailing list