[Asterisk-code-review] pjsip scheduler.c: Add ability to trace scheduled tasks. (asterisk[master])

Richard Mudgett asteriskteam at digium.com
Mon Apr 9 18:50:37 CDT 2018


Richard Mudgett has uploaded this change for review. ( https://gerrit.asterisk.org/8756


Change subject: pjsip_scheduler.c: Add ability to trace scheduled tasks.
......................................................................

pjsip_scheduler.c: Add ability to trace scheduled tasks.

When a scheduled task is created you can pass in the
AST_SIP_SCHED_TASK_TRACK flag.  This new flag causes scheduling events to
be logged.

Change-Id: I91967eb3d5a220915ce86881a28af772f9a7f56b
---
M include/asterisk/res_pjsip.h
M res/res_pjsip/pjsip_scheduler.c
2 files changed, 32 insertions(+), 4 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/56/8756/1

diff --git a/include/asterisk/res_pjsip.h b/include/asterisk/res_pjsip.h
index b01d6f5..f06aec4 100644
--- a/include/asterisk/res_pjsip.h
+++ b/include/asterisk/res_pjsip.h
@@ -1620,16 +1620,23 @@
 	 */
 	AST_SIP_SCHED_TASK_DATA_FREE = ( 1 << 3 ),
 
-	/*! \brief AST_SIP_SCHED_TASK_PERIODIC
-	 * The task is scheduled at multiples of interval
+	/*!
+	 * \brief The task is scheduled at multiples of interval
 	 * \see Interval
 	 */
 	AST_SIP_SCHED_TASK_PERIODIC = (0 << 4),
-	/*! \brief AST_SIP_SCHED_TASK_DELAY
-	 * The next invocation of the task is at last finish + interval
+	/*!
+	 * \brief The next invocation of the task is at last finish + interval
 	 * \see Interval
 	 */
 	AST_SIP_SCHED_TASK_DELAY = (1 << 4),
+	/*!
+	 * \brief The scheduled task's events are tracked in the debug log.
+	 * \details
+	 * Schedule events such as scheduling, running, rescheduling, canceling,
+	 * and destroying are logged about the task.
+	 */
+	AST_SIP_SCHED_TASK_TRACK = (1 << 5),
 };
 
 /*!
diff --git a/res/res_pjsip/pjsip_scheduler.c b/res/res_pjsip/pjsip_scheduler.c
index 4210664..65dd6e1 100644
--- a/res/res_pjsip/pjsip_scheduler.c
+++ b/res/res_pjsip/pjsip_scheduler.c
@@ -86,6 +86,9 @@
 		return -1;
 	}
 
+	if (schtd->flags & AST_SIP_SCHED_TASK_TRACK) {
+		ast_log(LOG_DEBUG, "Sched %p: Running %s\n", schtd, schtd->name);
+	}
 	ao2_lock(schtd);
 	schtd->last_start = ast_tvnow();
 	schtd->is_running = 1;
@@ -137,6 +140,10 @@
 	}
 
 	ao2_unlock(schtd);
+	if (schtd->flags & AST_SIP_SCHED_TASK_TRACK) {
+		ast_log(LOG_DEBUG, "Sched %p: Rescheduled %s for %d ms\n", schtd, schtd->name,
+			delay);
+	}
 
 	return 0;
 }
@@ -159,6 +166,9 @@
 		return 0;
 	}
 
+	if (schtd->flags & AST_SIP_SCHED_TASK_TRACK) {
+		ast_log(LOG_DEBUG, "Sched %p: Ready to run %s\n", schtd, schtd->name);
+	}
 	ao2_t_ref(schtd, +1, "Give ref to run_task()");
 	if (ast_sip_push_task(schtd->serializer, run_task, schtd)) {
 		/*
@@ -180,6 +190,10 @@
 {
 	int res;
 	int sched_id;
+
+	if (schtd->flags & AST_SIP_SCHED_TASK_TRACK) {
+		ast_log(LOG_DEBUG, "Sched %p: Canceling %s\n", schtd, schtd->name);
+	}
 
 	/*
 	 * Prevent any tasks in the serializer queue from
@@ -347,6 +361,9 @@
 {
 	struct ast_sip_sched_task *schtd = data;
 
+	if (schtd->flags & AST_SIP_SCHED_TASK_TRACK) {
+		ast_log(LOG_DEBUG, "Sched %p: Destructor %s\n", schtd, schtd->name);
+	}
 	if (schtd->flags & AST_SIP_SCHED_TASK_DATA_AO2) {
 		/* release our own ref, then release the callers if asked to do so */
 		ao2_ref(schtd->task_data, (schtd->flags & AST_SIP_SCHED_TASK_DATA_FREE) ? -2 : -1);
@@ -387,6 +404,10 @@
 		task_id = ast_atomic_fetchadd_int(&task_count, 1);
 		sprintf(schtd->name, "task_%08x", task_id);
 	}
+	if (schtd->flags & AST_SIP_SCHED_TASK_TRACK) {
+		ast_log(LOG_DEBUG, "Sched %p: Scheduling %s for %d ms\n", schtd, schtd->name,
+			interval);
+	}
 	schtd->when_queued = ast_tvnow();
 	if (!(schtd->flags & AST_SIP_SCHED_TASK_DELAY)) {
 		schtd->next_periodic = ast_tvadd(schtd->when_queued,

-- 
To view, visit https://gerrit.asterisk.org/8756
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I91967eb3d5a220915ce86881a28af772f9a7f56b
Gerrit-Change-Number: 8756
Gerrit-PatchSet: 1
Gerrit-Owner: Richard Mudgett <rmudgett at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180409/a078aa4f/attachment.html>


More information about the asterisk-code-review mailing list