diff --git a/src/sqlite3.c b/src/sqlite3.c index ea2fbcb3e067fcb6c20922236ca24a629bb13ce4..9742d16a33dec0596d16a1ec23cc5288dc1f001b 100644 --- a/src/sqlite3.c +++ b/src/sqlite3.c @@ -66072,6 +66072,7 @@ static int walBeginShmUnreliable(Wal *pWal, int *pChanged){ ** so it takes care to hold an exclusive lock on the corresponding ** WAL_READ_LOCK() while changing values. */ +static void printLockInfoUsingWal(Wal *pWal); static int walTryBeginRead(Wal *pWal, int *pChanged, int useWal, int cnt){ volatile WalCkptInfo *pInfo; /* Checkpoint information in wal-index */ u32 mxReadMark; /* Largest aReadMark[] value */ @@ -66109,6 +66110,9 @@ static int walTryBeginRead(Wal *pWal, int *pChanged, int useWal, int cnt){ return SQLITE_PROTOCOL; } if( cnt>=10 ) nDelay = (cnt-9)*(cnt-9)*39; +#if SQLITE_OS_UNIX + if( cnt>=15 ) printLockInfoUsingWal(pWal); +#endif /* SQLITE_OS_UNIX */ sqlite3OsSleep(pWal->pVfs, nDelay); } @@ -71028,6 +71032,7 @@ static void pageReinit(DbPage *pData){ } } +static void printLockInfoUsingPager(Pager *pPager); /* ** Invoke the busy handler for a btree. */ @@ -71035,6 +71040,9 @@ static int btreeInvokeBusyHandler(void *pArg){ BtShared *pBt = (BtShared*)pArg; assert( pBt->db ); assert( sqlite3_mutex_held(pBt->db->mutex) ); +#if SQLITE_OS_UNIX + printLockInfoUsingPager( pBt->pPager ); +#endif /* SQLITE_OS_UNIX */ return sqlite3InvokeBusyHandler(&pBt->db->busyHandler); } @@ -246205,6 +246213,102 @@ export_finish: /************** End file hw_codec.c *****************************************/ #endif +#if SQLITE_OS_UNIX +#define DB_LOCK_NUM 3 +#define WAL_LOCK_NUM 8 +#define WAL_READ_LOCK_POS 3 +static void printLockInfo(unixFile *uFile_db, int walStat) +{ + const char *lock_type[DB_LOCK_NUM] = {"F_RDLCK", "F_WRLCK", "F_UNLCK"}; + + sqlite3_log(SQLITE_WARNING, "*** SQLITE_LOG DB Lock ***\n"); + if( uFile_db==NULL ){ + sqlite3_log(SQLITE_WARNING, "NO DB FILE !\n"); + return; + } + + /* File Lock Info */ + int fd_db = uFile_db->h; + const off_t start_list[DB_LOCK_NUM] = {PENDING_BYTE, RESERVED_BYTE, SHARED_FIRST}; + const off_t len_list[DB_LOCK_NUM] = {1, 1, SHARED_SIZE}; + const char *lock_name_list[DB_LOCK_NUM] = {"pending lock ", "reserved lock", "shared lock "}; + + for(int i=0; ipShm==NULL ){ + sqlite3_log(SQLITE_ERROR, "DB Shm is NULL!\n"); + }else{ + for( int i=0; ipShm->pShmNode->aLock[i] ){ + sqlite3_log(SQLITE_WARNING, " thrad WAL Lock[%d] for DB file: %d\n", i, uFile_db->pShm->pShmNode->aLock[i]); + } + } + } +} + +#ifndef SQLITE_OMIT_WAL +static void printLockInfoUsingWal(Wal *pWal) +{ + if( pWal==NULL ){ + sqlite3_log(SQLITE_ERROR, "Wal ptr is NULL!\n"); + return; + } + printLockInfo((unixFile *)(pWal->pDbFd), 1); +} +#endif /* #ifndef SQLITE_OMIT_WAL */ + +static void printLockInfoUsingPager(Pager *pPager) +{ + if( pPager==NULL ){ + sqlite3_log(SQLITE_ERROR, "Pager ptr is NULL!\n"); + return; + } +#ifndef SQLITE_OMIT_WAL + printLockInfo((unixFile *)(pPager->fd), pPager->pWal!=NULL); +#else /* #ifndef SQLITE_OMIT_WAL */ + printLockInfo((unixFile *)(pPager->fd), 0); +#endif /* #ifndef SQLITE_OMIT_WAL */ +} +#endif /* SQLITE_OS_UNIX */ + // hw export the symbols #ifdef SQLITE_EXPORT_SYMBOLS #if defined(__GNUC__)