<p>Joshua C. Colp <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/11017">View Change</a></p><div style="white-space:pre-wrap">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
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">stasis: Store subscriber uniqueids with topic statistics.<br><br>This change provides an easier mechanism to determine which<br>subscribers are subscribed to a topic. Using this you can<br>inspect the specific subscribers for further details.<br><br>Change-Id: I8deea21703cd5c5357b85593b46c3eaf24e18c0c<br>---<br>M main/stasis.c<br>1 file changed, 29 insertions(+), 6 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/main/stasis.c b/main/stasis.c</span><br><span>index 5835a5a..397e501 100644</span><br><span>--- a/main/stasis.c</span><br><span>+++ b/main/stasis.c</span><br><span>@@ -349,8 +349,8 @@</span><br><span> int messages_not_dispatched;</span><br><span> /*! \brief The number of messages that were dispatched to at least 1 subscriber */</span><br><span> int messages_dispatched;</span><br><span style="color: hsl(0, 100%, 40%);">- /*! \brief The number of subscribers to this topic */</span><br><span style="color: hsl(0, 100%, 40%);">- int subscriber_count;</span><br><span style="color: hsl(120, 100%, 40%);">+ /*! \brief The ids of the subscribers to this topic */</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ao2_container *subscribers;</span><br><span> /*! \brief Name of the topic */</span><br><span> char name[0];</span><br><span> };</span><br><span>@@ -407,15 +407,28 @@</span><br><span> }</span><br><span> </span><br><span> #ifdef AST_DEVMODE</span><br><span style="color: hsl(120, 100%, 40%);">+static void topic_statistics_destroy(void *obj)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ struct stasis_topic_statistics *statistics = obj;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_cleanup(statistics->subscribers);</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> static struct stasis_topic_statistics *stasis_topic_statistics_create(const char *name)</span><br><span> {</span><br><span> struct stasis_topic_statistics *statistics;</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- statistics = ao2_alloc(sizeof(*statistics) + strlen(name) + 1, NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+ statistics = ao2_alloc(sizeof(*statistics) + strlen(name) + 1, topic_statistics_destroy);</span><br><span> if (!statistics) {</span><br><span> return NULL;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ statistics->subscribers = ast_str_container_alloc(1);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!statistics->subscribers) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_ref(statistics, -1);</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> strcpy(statistics->name, name); /* SAFE */</span><br><span> ao2_link(topic_statistics, statistics);</span><br><span> </span><br><span>@@ -1000,7 +1013,7 @@</span><br><span> }</span><br><span> </span><br><span> #ifdef AST_DEVMODE</span><br><span style="color: hsl(0, 100%, 40%);">- topic->statistics->subscriber_count += 1;</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_str_container_add(topic->statistics->subscribers, stasis_subscription_uniqueid(sub));</span><br><span> #endif</span><br><span> </span><br><span> ao2_unlock(topic);</span><br><span>@@ -1023,7 +1036,7 @@</span><br><span> </span><br><span> #ifdef AST_DEVMODE</span><br><span> if (!res) {</span><br><span style="color: hsl(0, 100%, 40%);">- topic->statistics->subscriber_count -= 1;</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_str_container_remove(topic->statistics->subscribers, stasis_subscription_uniqueid(sub));</span><br><span> }</span><br><span> #endif</span><br><span> </span><br><span>@@ -2294,6 +2307,8 @@</span><br><span> static char *statistics_show_topic(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)</span><br><span> {</span><br><span> struct stasis_topic_statistics *statistics;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ao2_iterator i;</span><br><span style="color: hsl(120, 100%, 40%);">+ char *uniqueid;</span><br><span> </span><br><span> switch (cmd) {</span><br><span> case CLI_INIT:</span><br><span>@@ -2325,7 +2340,15 @@</span><br><span> ast_cli(a->fd, "Number of messages that went to at least one subscriber: %d\n", statistics->messages_dispatched);</span><br><span> ast_cli(a->fd, "Lowest amount of time (in milliseconds) spent dispatching message: %ld\n", statistics->lowest_time_dispatched);</span><br><span> ast_cli(a->fd, "Highest amount of time (in milliseconds) spent dispatching messages: %ld\n", statistics->highest_time_dispatched);</span><br><span style="color: hsl(0, 100%, 40%);">- ast_cli(a->fd, "Number of subscribers: %d\n", statistics->subscriber_count);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_cli(a->fd, "Number of subscribers: %d\n", ao2_container_count(statistics->subscribers));</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_cli(a->fd, "Subscribers:\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ i = ao2_iterator_init(statistics->subscribers, 0);</span><br><span style="color: hsl(120, 100%, 40%);">+ while ((uniqueid = ao2_iterator_next(&i))) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_cli(a->fd, "\t%s\n", uniqueid);</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_ref(uniqueid, -1);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_iterator_destroy(&i);</span><br><span> </span><br><span> ao2_ref(statistics, -1);</span><br><span> </span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/11017">change 11017</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/11017"/><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-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: I8deea21703cd5c5357b85593b46c3eaf24e18c0c </div>
<div style="display:none"> Gerrit-Change-Number: 11017 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Joshua C. Colp <jcolp@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation (1000185) </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Joshua C. Colp <jcolp@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Kevin Harwell <kharwell@digium.com> </div>