<p>Jenkins2 <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/6763">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Corey Farrell: Looks good to me, but someone else must approve
Kevin Harwell: Looks good to me, approved
Jenkins2: Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">cdr.c: Defer getting ao2_global_obj_ref() until needed.<br><br>The CDR performance gets worse the further it gets behind in processing<br>stasis messages. One of the reasons is we were getting the global config<br>even if we didn't need it.<br><br>* Most uses of the global config were only needed on off nominal code<br>paths so it makes sense to not get it until absolutely needed.<br><br>ASTERISK-27335<br><br>Change-Id: I00c63b7ec233e5bfffd5d976f05568613d3c2365<br>---<br>M main/cdr.c<br>1 file changed, 40 insertions(+), 41 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/main/cdr.c b/main/cdr.c<br>index 1481ae7..65fbb1f 100644<br>--- a/main/cdr.c<br>+++ b/main/cdr.c<br>@@ -950,6 +950,28 @@<br> }<br> <br> /*!<br>+ * \internal<br>+ * \brief Determine if CDR flag is configured.<br>+ *<br>+ * \param cdr_flag The configured CDR flag to check.<br>+ *<br>+ * \retval 0 if the CDR flag is not configured.<br>+ * \retval non-zero if the CDR flag is configured.<br>+ *<br>+ * \return Nothing<br>+ */<br>+static int is_cdr_flag_set(unsigned int cdr_flag)<br>+{<br>+ struct module_config *mod_cfg;<br>+ int flag_set;<br>+<br>+ mod_cfg = ao2_global_obj_ref(module_configs);<br>+ flag_set = mod_cfg && ast_test_flag(&mod_cfg->general->settings, cdr_flag);<br>+ ao2_cleanup(mod_cfg);<br>+ return flag_set;<br>+}<br>+<br>+/*!<br> * \brief Return whether or not a channel has changed its state in the dialplan, subject<br> * to endbeforehexten logic<br> *<br>@@ -962,12 +984,9 @@<br> static int snapshot_cep_changed(struct ast_channel_snapshot *old_snapshot,<br> struct ast_channel_snapshot *new_snapshot)<br> {<br>- RAII_VAR(struct module_config *, mod_cfg,<br>- ao2_global_obj_ref(module_configs), ao2_cleanup);<br>-<br> /* If we ignore hangup logic, don't indicate that we're executing anything new */<br>- if (ast_test_flag(&mod_cfg->general->settings, CDR_END_BEFORE_H_EXTEN)<br>- && ast_test_flag(&new_snapshot->softhangup_flags, AST_SOFTHANGUP_HANGUP_EXEC)) {<br>+ if (ast_test_flag(&new_snapshot->softhangup_flags, AST_SOFTHANGUP_HANGUP_EXEC)<br>+ && is_cdr_flag_set(CDR_END_BEFORE_H_EXTEN)) {<br> return 0;<br> }<br> <br>@@ -975,10 +994,11 @@<br> * will attempt to clear the application and restore the dummy originate application<br> * of "AppDialX". Ignore application changes to AppDialX as a result.<br> */<br>- if (strcmp(new_snapshot->appl, old_snapshot->appl) && strncasecmp(new_snapshot->appl, "appdial", 7)<br>+ if (strcmp(new_snapshot->appl, old_snapshot->appl)<br>+ && strncasecmp(new_snapshot->appl, "appdial", 7)<br> && (strcmp(new_snapshot->context, old_snapshot->context)<br>- || strcmp(new_snapshot->exten, old_snapshot->exten)<br>- || new_snapshot->priority != old_snapshot->priority)) {<br>+ || strcmp(new_snapshot->exten, old_snapshot->exten)<br>+ || new_snapshot->priority != old_snapshot->priority)) {<br> return 1;<br> }<br> <br>@@ -1050,15 +1070,15 @@<br> */<br> static long cdr_object_get_billsec(struct cdr_object *cdr)<br> {<br>- RAII_VAR(struct module_config *, mod_cfg, ao2_global_obj_ref(module_configs), ao2_cleanup);<br> long int ms;<br> <br> if (ast_tvzero(cdr->answer)) {<br> return 0;<br> }<br>+<br> ms = ast_tvdiff_ms(ast_tvzero(cdr->end) ? ast_tvnow() : cdr->end, cdr->answer);<br>- if (ast_test_flag(&mod_cfg->general->settings, CDR_INITIATED_SECONDS)<br>- && (ms % 1000 >= 500)) {<br>+ if (ms % 1000 >= 500<br>+ && is_cdr_flag_set(CDR_INITIATED_SECONDS)) {<br> ms = (ms / 1000) + 1;<br> } else {<br> ms = ms / 1000;<br>@@ -1219,16 +1239,13 @@<br> */<br> static void cdr_object_set_disposition(struct cdr_object *cdr, int hangupcause)<br> {<br>- RAII_VAR(struct module_config *, mod_cfg,<br>- ao2_global_obj_ref(module_configs), ao2_cleanup);<br>-<br> /* Change the disposition based on the hang up cause */<br> switch (hangupcause) {<br> case AST_CAUSE_BUSY:<br> cdr->disposition = AST_CDR_BUSY;<br> break;<br> case AST_CAUSE_CONGESTION:<br>- if (!ast_test_flag(&mod_cfg->general->settings, CDR_CONGESTION)) {<br>+ if (!is_cdr_flag_set(CDR_CONGESTION)) {<br> cdr->disposition = AST_CDR_FAILED;<br> } else {<br> cdr->disposition = AST_CDR_CONGESTION;<br>@@ -1295,10 +1312,8 @@<br> */<br> static void cdr_object_check_party_a_hangup(struct cdr_object *cdr)<br> {<br>- RAII_VAR(struct module_config *, mod_cfg, ao2_global_obj_ref(module_configs), ao2_cleanup);<br>-<br>- if (ast_test_flag(&mod_cfg->general->settings, CDR_END_BEFORE_H_EXTEN)<br>- && ast_test_flag(&cdr->party_a.snapshot->softhangup_flags, AST_SOFTHANGUP_HANGUP_EXEC)) {<br>+ if (ast_test_flag(&cdr->party_a.snapshot->softhangup_flags, AST_SOFTHANGUP_HANGUP_EXEC)<br>+ && is_cdr_flag_set(CDR_END_BEFORE_H_EXTEN)) {<br> cdr_object_finalize(cdr);<br> }<br> <br>@@ -1361,13 +1376,11 @@<br> <br> static int base_process_party_a(struct cdr_object *cdr, struct ast_channel_snapshot *snapshot)<br> {<br>- RAII_VAR(struct module_config *, mod_cfg, ao2_global_obj_ref(module_configs), ao2_cleanup);<br>-<br> ast_assert(strcasecmp(snapshot->name, cdr->party_a.snapshot->name) == 0);<br> <br> /* Finalize the CDR if we're in hangup logic and we're set to do so */<br> if (ast_test_flag(&snapshot->softhangup_flags, AST_SOFTHANGUP_HANGUP_EXEC)<br>- && ast_test_flag(&mod_cfg->general->settings, CDR_END_BEFORE_H_EXTEN)) {<br>+ && is_cdr_flag_set(CDR_END_BEFORE_H_EXTEN)) {<br> cdr_object_finalize(cdr);<br> return 0;<br> }<br>@@ -1655,9 +1668,6 @@<br> */<br> static enum ast_cdr_disposition dial_status_to_disposition(const char *dial_status)<br> {<br>- RAII_VAR(struct module_config *, mod_cfg,<br>- ao2_global_obj_ref(module_configs), ao2_cleanup);<br>-<br> if (!strcmp(dial_status, "ANSWER")) {<br> return AST_CDR_ANSWERED;<br> } else if (!strcmp(dial_status, "BUSY")) {<br>@@ -1665,7 +1675,7 @@<br> } else if (!strcmp(dial_status, "CANCEL") || !strcmp(dial_status, "NOANSWER")) {<br> return AST_CDR_NOANSWER;<br> } else if (!strcmp(dial_status, "CONGESTION")) {<br>- if (!ast_test_flag(&mod_cfg->general->settings, CDR_CONGESTION)) {<br>+ if (!is_cdr_flag_set(CDR_CONGESTION)) {<br> return AST_CDR_FAILED;<br> } else {<br> return AST_CDR_CONGESTION;<br>@@ -1875,11 +1885,8 @@<br> <br> static int finalized_state_process_party_a(struct cdr_object *cdr, struct ast_channel_snapshot *snapshot)<br> {<br>- RAII_VAR(struct module_config *, mod_cfg,<br>- ao2_global_obj_ref(module_configs), ao2_cleanup);<br>-<br> if (ast_test_flag(&snapshot->softhangup_flags, AST_SOFTHANGUP_HANGUP_EXEC)<br>- && ast_test_flag(&mod_cfg->general->settings, CDR_END_BEFORE_H_EXTEN)) {<br>+ && is_cdr_flag_set(CDR_END_BEFORE_H_EXTEN)) {<br> return 0;<br> }<br> <br>@@ -2051,13 +2058,10 @@<br> static int check_new_cdr_needed(struct ast_channel_snapshot *old_snapshot,<br> struct ast_channel_snapshot *new_snapshot)<br> {<br>- RAII_VAR(struct module_config *, mod_cfg,<br>- ao2_global_obj_ref(module_configs), ao2_cleanup);<br>-<br> /* If we're dead, we don't need a new CDR */<br> if (!new_snapshot<br> || (ast_test_flag(&new_snapshot->softhangup_flags, AST_SOFTHANGUP_HANGUP_EXEC)<br>- && ast_test_flag(&mod_cfg->general->settings, CDR_END_BEFORE_H_EXTEN))) {<br>+ && is_cdr_flag_set(CDR_END_BEFORE_H_EXTEN))) {<br> return 0;<br> }<br> <br>@@ -2657,8 +2661,7 @@<br> <br> int ast_cdr_is_enabled(void)<br> {<br>- RAII_VAR(struct module_config *, mod_cfg, ao2_global_obj_ref(module_configs), ao2_cleanup);<br>- return ast_test_flag(&mod_cfg->general->settings, CDR_ENABLED);<br>+ return is_cdr_flag_set(CDR_ENABLED);<br> }<br> <br> int ast_cdr_backend_suspend(const char *name)<br>@@ -3132,13 +3135,9 @@<br> <br> cdr = cdr_object_get_by_name(channel_name);<br> if (!cdr) {<br>- RAII_VAR(struct module_config *, mod_cfg,<br>- ao2_global_obj_ref(module_configs), ao2_cleanup);<br>-<br>- if (ast_test_flag(&mod_cfg->general->settings, CDR_ENABLED)) {<br>+ if (is_cdr_flag_set(CDR_ENABLED)) {<br> ast_log(AST_LOG_ERROR, "Unable to find CDR for channel %s\n", channel_name);<br> }<br>-<br> return 0;<br> }<br> <br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/6763">change 6763</a>. To unsubscribe, 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/6763"/><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: I00c63b7ec233e5bfffd5d976f05568613d3c2365 </div>
<div style="display:none"> Gerrit-Change-Number: 6763 </div>
<div style="display:none"> Gerrit-PatchSet: 2 </div>
<div style="display:none"> Gerrit-Owner: Richard Mudgett <rmudgett@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Corey Farrell <git@cfware.com> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins2 </div>
<div style="display:none"> Gerrit-Reviewer: Kevin Harwell <kharwell@digium.com> </div>