From 2ffba2873e85bb5c7f9fcb025f9c28c4bb738b48 Mon Sep 17 00:00:00 2001 From: Benny Prijono Date: Tue, 5 Jun 2012 10:41:17 +0000 Subject: Re #1527: added debugging facility to the timer heap. By enabling PJ_TIMER_DEBUG, application can use pj_timer_heap_dump() or pjsip_endpt_dump() to dump the timer entries along with the source location where it is scheduled from. The macro will also enable dumping the timer heap entries when the SIP endpoint is being destroyed git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@4154 74dad513-b988-da41-8d7b-12977e46ad98 --- pjlib/src/pj/timer.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) (limited to 'pjlib/src') diff --git a/pjlib/src/pj/timer.c b/pjlib/src/pj/timer.c index 573c7ecb..ad037068 100644 --- a/pjlib/src/pj/timer.c +++ b/pjlib/src/pj/timer.c @@ -34,6 +34,9 @@ #include #include #include +#include + +#define THIS_FILE "timer.c" #define HEAP_PARENT(X) (X == 0 ? 0 : (((X) - 1) / 2)) #define HEAP_LEFT(X) (((X)+(X))+1) @@ -452,9 +455,17 @@ PJ_DEF(pj_timer_entry*) pj_timer_entry_init( pj_timer_entry *entry, return entry; } +#if PJ_TIMER_DEBUG +PJ_DEF(pj_status_t) pj_timer_heap_schedule_dbg( pj_timer_heap_t *ht, + pj_timer_entry *entry, + const pj_time_val *delay, + const char *src_file, + int src_line) +#else PJ_DEF(pj_status_t) pj_timer_heap_schedule( pj_timer_heap_t *ht, pj_timer_entry *entry, const pj_time_val *delay) +#endif { pj_status_t status; pj_time_val expires; @@ -465,6 +476,10 @@ PJ_DEF(pj_status_t) pj_timer_heap_schedule( pj_timer_heap_t *ht, /* Prevent same entry from being scheduled more than once */ PJ_ASSERT_RETURN(entry->_timer_id < 1, PJ_EINVALIDOP); +#if PJ_TIMER_DEBUG + entry->src_file = src_file; + entry->src_line = src_line; +#endif pj_gettickcount(&expires); PJ_TIME_VAL_ADD(expires, *delay); @@ -552,3 +567,44 @@ PJ_DEF(pj_status_t) pj_timer_heap_earliest_time( pj_timer_heap_t * ht, return PJ_SUCCESS; } +#if PJ_TIMER_DEBUG +PJ_DEF(void) pj_timer_heap_dump(pj_timer_heap_t *ht) +{ + lock_timer_heap(ht); + + PJ_LOG(3,(THIS_FILE, "Dumping timer heap:")); + PJ_LOG(3,(THIS_FILE, " Cur size: %d entries, max: %d", + (int)ht->cur_size, (int)ht->max_size)); + + if (ht->cur_size) { + unsigned i; + pj_time_val now; + + PJ_LOG(3,(THIS_FILE, " Entries: ")); + PJ_LOG(3,(THIS_FILE, " _id\tId\tElapsed\tSource")); + PJ_LOG(3,(THIS_FILE, " ----------------------------------")); + + pj_gettickcount(&now); + + for (i=0; i<(unsigned)ht->cur_size; ++i) { + pj_timer_entry *e = ht->heap[i]; + pj_time_val delta; + + if (PJ_TIME_VAL_LTE(e->_timer_value, now)) + delta.sec = delta.msec = 0; + else { + delta = e->_timer_value; + PJ_TIME_VAL_SUB(delta, now); + } + + PJ_LOG(3,(THIS_FILE, " %d\t%d\t%d.%03d\t%s:%d", + e->_timer_id, e->id, + (int)delta.sec, (int)delta.msec, + e->src_file, e->src_line)); + } + } + + unlock_timer_heap(ht); +} +#endif + -- cgit v1.2.3