aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormurf <murf@f38db490-d61c-443f-a65b-d21fe96a405b>2008-04-16 20:54:41 +0000
committermurf <murf@f38db490-d61c-443f-a65b-d21fe96a405b>2008-04-16 20:54:41 +0000
commitc99aa3db824dfb5a6eddf4d7d96685e8eb1767d6 (patch)
tree18e50329931323a287b2b1dff864083062d3cf62
parent2076b702796ef1f3e8f02ff545c5b5b6869806c9 (diff)
A small enhancement-- I added the routine log_show_lock to utils.c, which if the mentioned lock has been acquired, this routine will log to the console the normal info about that lock you'd see from the CLI when you do a 'core show locks'. It's solely for debug-- if the lock is NOT acquired, there is no output. I use it to show 'unexpected' locks, to see where/why a lock is pre-locked. This command is to be called from points of interest, like just before a trylock, and helps to spot fleeting, highly temporal locks that normally are not locked...
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@114187 f38db490-d61c-443f-a65b-d21fe96a405b
-rw-r--r--include/asterisk/lock.h12
-rw-r--r--main/utils.c50
2 files changed, 61 insertions, 1 deletions
diff --git a/include/asterisk/lock.h b/include/asterisk/lock.h
index 36c25a87d..f352a2d7d 100644
--- a/include/asterisk/lock.h
+++ b/include/asterisk/lock.h
@@ -186,6 +186,18 @@ void ast_remove_lock_info(void *lock_addr);
#define ast_remove_lock_info(ignore)
#endif
+
+
+/*!
+ * \brief log info for the current lock with ast_log().
+ *
+ * this function would be mostly for debug. If you come across a lock
+ * that is unexpectedly but momentarily locked, and you wonder who
+ * are fighting with for the lock, this routine could be called, IF
+ * you have the thread debugging stuff turned on.
+ */
+void log_show_lock(void *this_lock_addr);
+
static void __attribute__((constructor)) init_empty_mutex(void)
{
memset(&empty_mutex, 0, sizeof(empty_mutex));
diff --git a/main/utils.c b/main/utils.c
index a55620ee3..f831d7da4 100644
--- a/main/utils.c
+++ b/main/utils.c
@@ -714,6 +714,54 @@ static const char *locktype2str(enum ast_lock_type type)
return "UNKNOWN";
}
+void log_show_lock(void *this_lock_addr)
+{
+ struct thr_lock_info *lock_info;
+ struct ast_str *str;
+
+ pthread_mutex_lock(&lock_infos_lock.mutex);
+ AST_LIST_TRAVERSE(&lock_infos, lock_info, entry) {
+ int i;
+ pthread_mutex_lock(&lock_info->lock);
+ for (i = 0; str && i < lock_info->num_locks; i++) {
+ int j;
+ ast_mutex_t *lock;
+ if (lock_info->locks[i].lock_addr == this_lock_addr) {
+
+ ast_log(LOG_NOTICE, "---> %sLock #%d (%s): %s %d %s %s %p (%d)\n",
+ lock_info->locks[i].pending > 0 ? "Waiting for " : lock_info->locks[i].pending < 0 ? "Tried and failed to get " : "",
+ i,
+ lock_info->locks[i].file,
+ locktype2str(lock_info->locks[i].type),
+ lock_info->locks[i].line_num,
+ lock_info->locks[i].func,
+ lock_info->locks[i].lock_name,
+ lock_info->locks[i].lock_addr,
+ lock_info->locks[i].times_locked);
+
+ if (!lock_info->locks[i].pending || lock_info->locks[i].pending == -1)
+ continue;
+
+ /* We only have further details for mutexes right now */
+ if (lock_info->locks[i].type != AST_MUTEX)
+ continue;
+
+ lock = lock_info->locks[i].lock_addr;
+
+ ast_reentrancy_lock(lock);
+ for (j = 0; str && j < lock->reentrancy; j++) {
+ ast_log(LOG_NOTICE, "--- ---> Locked Here: %s line %d (%s)\n",
+ lock->file[j], lock->lineno[j], lock->func[j]);
+ }
+ ast_reentrancy_unlock(lock);
+ }
+ }
+ pthread_mutex_unlock(&lock_info->lock);
+ }
+ pthread_mutex_unlock(&lock_infos_lock.mutex);
+}
+
+
static char *handle_show_locks(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
struct thr_lock_info *lock_info;
@@ -740,7 +788,7 @@ static char *handle_show_locks(struct ast_cli_entry *e, int cmd, struct ast_cli_
"=== Currently Held Locks ==============================================\n"
"=======================================================================\n"
"===\n"
- "=== <file> <line num> <function> <lock name> <lock addr> (times locked)\n"
+ "=== <pending> <lock#> (<file>): <lock type> <line num> <function> <lock name> <lock addr> (times locked)\n"
"===\n");
if (!str)