Changeset 1074

Show
Ignore:
Timestamp:
04/30/08 08:24:55 (16 years ago)
Author:
ppalmers
Message:

implement debug lock tracing

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/libffado/config.h.in

    r1072 r1074  
    6161// max amount of function pointers to keep track of 
    6262#define DEBUG_MAX_BACKTRACE_FUNCTIONS_SEEN  64 
     63 
     64// lock debugging 
     65#define DEBUG_LOCK_COLLISION_TRACING         1 
    6366 
    6467// make this zero to disable the most extreme 
  • trunk/libffado/src/debugmodule/debugmodule.cpp

    r1046 r1074  
    640640    pthread_mutex_unlock(&m_backtrace_lock); 
    641641} 
     642 
     643void * 
     644DebugModuleManager::getBacktracePtr(int id) 
     645{ 
     646    int nptrs; 
     647    void *retval = NULL; 
     648 
     649    if(id >= DEBUG_MAX_BACKTRACE_LENGTH) { 
     650        return NULL; 
     651    } 
     652 
     653    pthread_mutex_lock(&m_backtrace_lock); 
     654    nptrs = backtrace(m_backtrace_buffer, id+1); 
     655    if(id<nptrs) { 
     656        retval = m_backtrace_buffer[id]; 
     657    } 
     658    pthread_mutex_unlock(&m_backtrace_lock); 
     659     
     660    return retval; 
     661} 
    642662#endif 
    643663 
  • trunk/libffado/src/debugmodule/debugmodule.h

    r1046 r1074  
    246246 * Backtrace support 
    247247 */ 
    248 #ifdef DEBUG 
    249     #if DEBUG_BACKTRACE_SUPPORT 
    250         #define debugPrintBacktrace( _SIZE_ )                       \ 
    251             DebugModuleManager::instance()->printBacktrace( _SIZE_ ); 
    252     #endif 
     248#if DEBUG_BACKTRACE_SUPPORT 
     249    #define debugPrintBacktrace( _SIZE_ )                       \ 
     250        DebugModuleManager::instance()->printBacktrace( _SIZE_ ); 
     251    #define debugBacktraceGet( _ID_ )                       \ 
     252        DebugModuleManager::instance()->getBacktracePtr( _ID_ ); 
    253253#else 
    254254    #define debugPrintBacktrace( _SIZE_ ) 
     255    #define debugBacktraceGet( _ID_ )       NULL  
    255256#endif 
    256257 
     
    333334#if DEBUG_BACKTRACE_SUPPORT 
    334335    void printBacktrace(int len); 
     336    void *getBacktracePtr(int id); 
    335337#endif 
    336338 
  • trunk/libffado/src/libutil/PosixMutex.cpp

    r976 r1074  
    2424#include "PosixMutex.h" 
    2525 
     26// disable collision tracing for non-debug builds 
     27#ifndef DEBUG 
     28    #undef DEBUG_LOCK_COLLISION_TRACING 
     29    #define DEBUG_LOCK_COLLISION_TRACING 0 
     30#endif 
     31 
     32// check whether backtracing is enabled 
     33#if DEBUG_LOCK_COLLISION_TRACING 
     34    #if DEBUG_BACKTRACE_SUPPORT 
     35    // ok 
     36    #else 
     37        #error cannot enable lock tracing without backtrace support 
     38    #endif 
     39#endif 
     40 
    2641namespace Util 
    2742{ 
     
    3853    #endif 
    3954    pthread_mutex_init(&m_mutex, &attr); 
     55 
     56    #if DEBUG_LOCK_COLLISION_TRACING 
     57    m_locked_by = NULL; 
     58    #endif 
    4059} 
    4160 
     
    4968{ 
    5069    debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "(%p) lock\n", this); 
     70    #if DEBUG_LOCK_COLLISION_TRACING 
     71    if(TryLock()) { 
     72        // locking succeeded 
     73        m_locked_by = debugBacktraceGet(1); 
     74        debugOutput(DEBUG_LEVEL_VERBOSE, 
     75                    "%p has lock\n", 
     76                    m_locked_by); 
     77        return; 
     78    } else { 
     79        void *lock_try_by = debugBacktraceGet(1); 
     80        debugOutput(DEBUG_LEVEL_VERBOSE, 
     81                    "Lock collision: %p wants lock, %p has lock\n", 
     82                    lock_try_by); 
     83        pthread_mutex_lock(&m_mutex); 
     84    } 
     85    #else 
    5186    pthread_mutex_lock(&m_mutex); 
     87    #endif 
    5288} 
    5389 
  • trunk/libffado/src/libutil/PosixMutex.h

    r967 r1074  
    2424#ifndef __POSIX_MUTEX__ 
    2525#define __POSIX_MUTEX__ 
     26 
     27#include "config.h" 
    2628 
    2729#include "Mutex.h" 
     
    5557private: 
    5658    pthread_mutex_t m_mutex; 
     59 
     60    #if DEBUG_LOCK_COLLISION_TRACING 
     61    void *m_locked_by; 
     62    #endif 
    5763}; 
    5864