From 3a71cefb2f0e61071d8f6649e0cd4bdf5e26f589 Mon Sep 17 00:00:00 2001 From: Florent De Neve Date: Mon, 21 Oct 2024 11:32:31 -0400 Subject: [PATCH] Update SQLite with more logs, v3 --- Makefile | 2 +- libstuff/sqlite3.c | 38 +++++++++++++++++++++++++++++++++----- libstuff/sqlite3.h | 2 +- 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 71a34084a..8e23a986d 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,7 @@ INCLUDE = -I$(PROJECT) -I$(PROJECT)/mbedtls/include CXXFLAGS = -g -std=c++20 -fPIC -DSQLITE_ENABLE_NORMALIZE $(BEDROCK_OPTIM_COMPILE_FLAG) -Wall -Werror -Wformat-security -Wno-unqualified-std-cast-call -Wno-error=deprecated-declarations $(INCLUDE) # Amalgamation flags -AMALGAMATION_FLAGS = -Wno-unused-but-set-variable -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_STAT4 -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_SESSION -DSQLITE_ENABLE_PREUPDATE_HOOK -DSQLITE_ENABLE_UPDATE_DELETE_LIMIT -DSQLITE_ENABLE_NOOP_UPDATE -DSQLITE_MUTEX_ALERT_MILLISECONDS=20 -DHAVE_USLEEP=1 -DSQLITE_MAX_MMAP_SIZE=17592186044416ull -DSQLITE_SHARED_MAPPING -DSQLITE_ENABLE_NORMALIZE -DSQLITE_MAX_PAGE_COUNT=4294967294 -DSQLITE_DISABLE_PAGECACHE_OVERFLOW_STATS +AMALGAMATION_FLAGS = -Wno-unused-but-set-variable -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_STAT4 -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_SESSION -DSQLITE_ENABLE_PREUPDATE_HOOK -DSQLITE_ENABLE_UPDATE_DELETE_LIMIT -DSQLITE_ENABLE_NOOP_UPDATE -DSQLITE_MUTEX_ALERT_MILLISECONDS=20 -DHAVE_USLEEP=1 -DSQLITE_MAX_MMAP_SIZE=17592186044416ull -DSQLITE_SHARED_MAPPING -DSQLITE_ENABLE_NORMALIZE -DSQLITE_MAX_PAGE_COUNT=4294967294 -DSQLITE_DISABLE_PAGECACHE_OVERFLOW_STATS -DSQLITE_ENABLE_STMT_SCANSTATUS=1 # All our intermediate, dependency, object, etc files get hidden in here. INTERMEDIATEDIR = .build diff --git a/libstuff/sqlite3.c b/libstuff/sqlite3.c index 16be8c7ef..377325b33 100644 --- a/libstuff/sqlite3.c +++ b/libstuff/sqlite3.c @@ -18,7 +18,7 @@ ** separate file. This file contains only code for the core SQLite library. ** ** The content in this amalgamation comes from Fossil check-in -** 6deb4794f8e24dbb946069de1e5c34fbcd47. +** 08e1dea9c070c9a2d668d39ceb153bc8b6d1. */ #define SQLITE_CORE 1 #define SQLITE_AMALGAMATION 1 @@ -465,7 +465,7 @@ extern "C" { */ #define SQLITE_VERSION "3.47.0" #define SQLITE_VERSION_NUMBER 3047000 -#define SQLITE_SOURCE_ID "2024-10-10 15:28:18 6deb4794f8e24dbb946069de1e5c34fbcd4734162002f3bc7deb1a3f69adec05" +#define SQLITE_SOURCE_ID "2024-10-21 11:49:04 08e1dea9c070c9a2d668d39ceb153bc8b6d172e7273f6564a374c43055e84461" /* ** CAPI3REF: Run-Time Library Version Numbers @@ -18185,6 +18185,7 @@ struct sqlite3 { #define sqlite3PrepareTimeSet(x,y) sqlite3CommitTimeSet(x,y) SQLITE_PRIVATE void sqlite3PrepareTimeLog(const char *zSql, int nSql, u64 *aPrepareTime); +SQLITE_PRIVATE void sqlite3SchemaTimeLog(Vdbe *pVdbe); #define PREPARE_TIME_TIMEOUT (2 * 1000 * 1000) /* 2 second timeout */ @@ -93187,7 +93188,7 @@ SQLITE_PRIVATE void sqlite3CommitTimeLog(u64 *aCommit){ (aCommit[ii]==0 ? 0 : (int)(aCommit[ii] - i1)) ); } - sqlite3_log(SQLITE_WARNING, "slow commit (v=2): (%s)", zStr); + sqlite3_log(SQLITE_WARNING, "slow commit (v=3): (%s)", zStr); sqlite3_free(zStr); } } @@ -93215,11 +93216,25 @@ SQLITE_PRIVATE void sqlite3PrepareTimeLog(const char *zSql, int nSql, u64 *aPrep } if( nByte<0 ){ nByte = sqlite3Strlen30(zSql); } sqlite3_log(SQLITE_WARNING, - "slow prepare (v=2): (%s) [%.*s]", zStr, nByte, zSql + "slow prepare (v=3): (%s) [%.*s]", zStr, nByte, zSql ); sqlite3_free(zStr); } } +SQLITE_PRIVATE void sqlite3SchemaTimeLog(Vdbe *pVdbe){ + int ii; + char *zStr = 0; + for(ii=0; iinOp; ii++){ + VdbeOp *pOp = &pVdbe->aOp[ii]; + zStr = sqlite3_mprintf("%z%s(%s %lld %lld)", zStr, (zStr?" ":""), + (char*)sqlite3OpcodeName(pOp->opcode), pOp->nExec, pOp->nCycle + ); + } + sqlite3_log(SQLITE_WARNING, + "slow schema query (v=3): (%s) [%s]", zStr, pVdbe->zSql + ); + sqlite3_free(zStr); +} #ifndef SQLITE_OMIT_VIRTUALTABLE @@ -139681,6 +139696,11 @@ SQLITE_API int sqlite3_exec( while( rc==SQLITE_OK && zSql[0] ){ int nCol = 0; char **azVals = 0; + i64 tmStart = sqlite3STimeNow(); + u64 svFlags = db->flags; + if( db->init.busy ){ + db->flags |= SQLITE_StmtScanStatus; + } pStmt = 0; rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, &zLeftover); @@ -139741,6 +139761,9 @@ SQLITE_API int sqlite3_exec( } if( rc!=SQLITE_ROW ){ + if( db->init.busy && (sqlite3STimeNow()-tmStart)>PREPARE_TIME_TIMEOUT ){ + sqlite3SchemaTimeLog((Vdbe*)pStmt); + } rc = sqlite3VdbeFinalize((Vdbe *)pStmt); pStmt = 0; zSql = zLeftover; @@ -139749,6 +139772,11 @@ SQLITE_API int sqlite3_exec( } } + if( db->init.busy ){ + /* Clear the SQLITE_StmtScanStatus flag if it was clear at the top + ** of this loop. */ + db->flags &= (~SQLITE_StmtScanStatus | svFlags); + } sqlite3DbFree(db, azCols); azCols = 0; } @@ -257570,7 +257598,7 @@ static void fts5SourceIdFunc( ){ assert( nArg==0 ); UNUSED_PARAM2(nArg, apUnused); - sqlite3_result_text(pCtx, "fts5: 2024-10-10 15:28:18 6deb4794f8e24dbb946069de1e5c34fbcd4734162002f3bc7deb1a3f69adec05", -1, SQLITE_TRANSIENT); + sqlite3_result_text(pCtx, "fts5: 2024-10-21 11:49:04 08e1dea9c070c9a2d668d39ceb153bc8b6d172e7273f6564a374c43055e84461", -1, SQLITE_TRANSIENT); } /* diff --git a/libstuff/sqlite3.h b/libstuff/sqlite3.h index e485be1cb..655e42b07 100644 --- a/libstuff/sqlite3.h +++ b/libstuff/sqlite3.h @@ -148,7 +148,7 @@ extern "C" { */ #define SQLITE_VERSION "3.47.0" #define SQLITE_VERSION_NUMBER 3047000 -#define SQLITE_SOURCE_ID "2024-10-10 15:28:18 6deb4794f8e24dbb946069de1e5c34fbcd4734162002f3bc7deb1a3f69adec05" +#define SQLITE_SOURCE_ID "2024-10-21 11:49:04 08e1dea9c070c9a2d668d39ceb153bc8b6d172e7273f6564a374c43055e84461" /* ** CAPI3REF: Run-Time Library Version Numbers