Changeset 698 for trunk/libffado

Show
Ignore:
Timestamp:
11/04/07 03:19:01 (16 years ago)
Author:
ppalmers
Message:

- make backlog a compile time option
- do some performance optimization on the debugging code

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/libffado/src/debugmodule/debugmodule.cpp

    r693 r698  
    8484                         ... ) const 
    8585{ 
     86 
     87    // bypass for performance 
     88#ifdef IMPLEMENT_BACKLOG 
     89    if (level > BACKLOG_MIN_LEVEL  
     90        && level > m_level) { 
     91        return; 
     92    } 
     93#else 
     94    if ( level >m_level ) { 
     95        return; 
     96    } 
     97#endif 
     98 
    8699    const char *warning = "WARNING: message truncated!\n"; 
    87100    const int warning_size = 32; 
     
    105118    } 
    106119 
     120#ifdef IMPLEMENT_BACKLOG 
    107121    // print to backlog if necessary 
    108122    if (level <= BACKLOG_MIN_LEVEL) { 
    109123        DebugModuleManager::instance()->backlog_print( msg ); 
    110124    } 
     125#endif 
    111126 
    112127    // print to stderr if necessary 
     
    124139                    ... ) const 
    125140{ 
     141    // bypass for performance 
     142#ifdef IMPLEMENT_BACKLOG 
     143    if (level > BACKLOG_MIN_LEVEL  
     144        && level > m_level) { 
     145        return; 
     146    } 
     147#else 
     148    if ( level >m_level ) { 
     149        return; 
     150    } 
     151#endif 
     152 
    126153    const char *warning = "WARNING: message truncated!\n"; 
    127154    const int warning_size = 32; 
     
    170197    } 
    171198 
     199#ifdef IMPLEMENT_BACKLOG 
    172200    // print to backlog if necessary 
    173201    if (level <= BACKLOG_MIN_LEVEL) { 
    174202        DebugModuleManager::instance()->backlog_print( msg ); 
    175203    } 
     204#endif 
    176205 
    177206    // print to stderr if necessary 
     
    208237    , mb_outbuffer(0) 
    209238    , mb_overruns(0) 
     239#ifdef IMPLEMENT_BACKLOG 
    210240    , bl_mb_inbuffer(0) 
     241#endif 
    211242{ 
    212243 
     
    245276    pthread_cond_destroy(&mb_ready_cond); 
    246277 
     278#ifdef IMPLEMENT_BACKLOG 
     279    pthread_mutex_destroy(&bl_mb_write_lock); 
     280#endif 
     281 
    247282} 
    248283 
     
    263298    mb_initialized = 1; 
    264299 
     300#ifdef IMPLEMENT_BACKLOG 
    265301    pthread_mutex_init(&bl_mb_write_lock, NULL); 
     302#endif 
    266303 
    267304    if (pthread_create(&mb_writer_thread, NULL, &mb_thread_func, (void *)this) != 0) 
     
    377414} 
    378415 
     416#ifdef IMPLEMENT_BACKLOG 
    379417void 
    380418DebugModuleManager::showBackLog() 
     
    400438} 
    401439 
     440void 
     441DebugModuleManager::showBackLog(int nblines) 
     442{ 
     443     DebugModuleManager *m=DebugModuleManager::instance(); 
     444    // locking the flush lock ensures that the backlog is 
     445    // printed as one entity 
     446    pthread_mutex_lock(&m->mb_flush_lock); 
     447    fprintf(stderr, "=====================================================\n"); 
     448    fprintf(stderr, "* BEGIN OF BACKLOG PRINT\n"); 
     449    fprintf(stderr, "=====================================================\n"); 
     450 
     451    int lines_to_skip = BACKLOG_MB_BUFFERS - nblines; 
     452    if (lines_to_skip < 0) lines_to_skip = 0; 
     453    for (unsigned int i=0; i<BACKLOG_MB_BUFFERS;i++) { 
     454        if (lines_to_skip-- < 0) { 
     455            unsigned int idx=(i+bl_mb_inbuffer)%BACKLOG_MB_BUFFERS; 
     456            fputs(bl_mb_buffers[idx], stderr); 
     457        } 
     458    } 
     459    fprintf(stderr, "\n"); 
     460 
     461    fprintf(stderr, "=====================================================\n"); 
     462    fprintf(stderr, "* END OF BACKLOG PRINT\n"); 
     463    fprintf(stderr, "=====================================================\n"); 
     464    pthread_mutex_unlock(&m->mb_flush_lock); 
     465} 
     466#endif 
     467 
    402468void * 
    403469DebugModuleManager::mb_thread_func(void *arg) 
     
    424490} 
    425491 
     492#ifdef IMPLEMENT_BACKLOG 
    426493void 
    427494DebugModuleManager::backlog_print(const char *msg) 
     
    444511    // just bail out should it have failed 
    445512} 
     513#endif 
    446514 
    447515void 
  • trunk/libffado/src/debugmodule/debugmodule.h

    r693 r698  
    5252#define MB_BUFFERSIZE       DEBUG_MAX_MESSAGE_LENGTH 
    5353 
     54// #define IMPLEMENT_BACKLOG 
     55#ifdef IMPLEMENT_BACKLOG 
    5456// the backlog is a similar buffer as the message buffer 
    5557#define BACKLOG_MB_BUFFERS      (256) 
    5658#define BACKLOG_MB_NEXT(index)  (((index)+1) & (BACKLOG_MB_BUFFERS-1)) 
    57 #define BACKLOG_MIN_LEVEL       DEBUG_LEVEL_VERY_VERBOSE 
    58  
     59#define BACKLOG_MIN_LEVEL       DEBUG_LEVEL_VERBOSE 
     60#endif 
    5961 
    6062#define debugFatal( format, args... )                               \ 
     
    119121 
    120122#define flushDebugOutput()      DebugModuleManager::instance()->flush() 
    121 #define debugShowBackLog()      DebugModuleManager::instance()->showBackLog() 
     123 
     124#ifdef IMPLEMENT_BACKLOG 
     125 
     126#define debugShowBackLog()          DebugModuleManager::instance()->showBackLog() 
     127#define debugShowBackLogLines(x)    DebugModuleManager::instance()->showBackLog(x) 
     128 
     129#else 
     130#define debugShowBackLog() 
     131#define debugShowBackLogLines(x) 
     132 
     133#endif 
    122134 
    123135#ifdef DEBUG 
     
    229241    // much output in normal operation 
    230242    void showBackLog(); 
     243    void showBackLog(int nblines); 
    231244 
    232245protected: 
     
    258271    void mb_flush(); 
    259272 
     273#ifdef IMPLEMENT_BACKLOG 
    260274    // the backlog 
    261275    char bl_mb_buffers[BACKLOG_MB_BUFFERS][MB_BUFFERSIZE]; 
    262276    unsigned int bl_mb_inbuffer; 
    263277    pthread_mutex_t bl_mb_write_lock; 
     278#endif 
    264279 
    265280    static DebugModuleManager* m_instance;