diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/pager.c | 10 | ||||
-rw-r--r-- | src/pager.h | 1 | ||||
-rw-r--r-- | src/sqlite.h.in | 16 | ||||
-rw-r--r-- | src/status.c | 20 | ||||
-rw-r--r-- | src/test_malloc.c | 1 |
5 files changed, 45 insertions, 3 deletions
diff --git a/src/pager.c b/src/pager.c index 9844dafcd..ba72d0690 100644 --- a/src/pager.c +++ b/src/pager.c @@ -4855,6 +4855,16 @@ int sqlite3PagerRefcount(Pager *pPager){ } /* +** Return the approximate number of bytes of memory currently +** used by the pager and its associated cache. +*/ +int sqlite3PagerMemUsed(Pager *pPager){ + int perPageSize = pPager->pageSize + pPager->nExtra + 20; + return perPageSize*sqlite3PcachePagecount(pPager->pPCache) + + sqlite3MallocSize(pPager); +} + +/* ** Return the number of references to the specified page. */ int sqlite3PagerPageRefcount(DbPage *pPage){ diff --git a/src/pager.h b/src/pager.h index 0fe1917be..7d778c82c 100644 --- a/src/pager.h +++ b/src/pager.h @@ -136,6 +136,7 @@ int sqlite3PagerSharedLock(Pager *pPager); /* Functions used to query pager state and configuration. */ u8 sqlite3PagerIsreadonly(Pager*); int sqlite3PagerRefcount(Pager*); +int sqlite3PagerMemUsed(Pager*); const char *sqlite3PagerFilename(Pager*); const sqlite3_vfs *sqlite3PagerVfs(Pager*); sqlite3_file *sqlite3PagerFile(Pager*); diff --git a/src/sqlite.h.in b/src/sqlite.h.in index a6d1a7576..97b550064 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -5093,9 +5093,11 @@ int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag); ** ^This interface is used to retrieve runtime status information ** about a single [database connection]. ^The first argument is the ** database connection object to be interrogated. ^The second argument -** is the parameter to interrogate. ^Currently, the only allowed value -** for the second parameter is [SQLITE_DBSTATUS_LOOKASIDE_USED]. -** Additional options will likely appear in future releases of SQLite. +** is an integer constant, taken from the set of +** [SQLITE_DBSTATUS_LOOKASIDE_USED | SQLITE_DBSTATUS_*] macros, that +** determiness the parameter to interrogate. The set of +** [SQLITE_DBSTATUS_LOOKASIDE_USED | SQLITE_DBSTATUS_*] macros is likely +** to grow in future releases of SQLite. ** ** ^The current value of the requested parameter is written into *pCur ** and the highest instantaneous value is written into *pHiwtr. ^If @@ -5122,9 +5124,17 @@ int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg); ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt> ** <dd>This parameter returns the number of lookaside memory slots currently ** checked out.</dd>)^ +** +** <dt>SQLITE_DBSTATUS_CACHE_USED</dt> +** <dd>^This parameter returns the approximate number of of bytes of heap +** memory used by all pager caches associated with the database connection. +** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0. +** checked out.</dd>)^ ** </dl> */ #define SQLITE_DBSTATUS_LOOKASIDE_USED 0 +#define SQLITE_DBSTATUS_CACHE_USED 1 +#define SQLITE_DBSTATUS_MAX 1 /* Largest defined DBSTATUS */ /* diff --git a/src/status.c b/src/status.c index f4c77a910..f310f36d3 100644 --- a/src/status.c +++ b/src/status.c @@ -112,6 +112,26 @@ int sqlite3_db_status( } break; } + + /* + ** Return an approximation for the amount of memory currently used + ** by all pagers associated with the given database connection. The + ** highwater mark is meaningless and is returned as zero. + */ + case SQLITE_DBSTATUS_CACHE_USED: { + int totalUsed = 0; + int i; + for(i=0; i<db->nDb; i++){ + Btree *pBt = db->aDb[i].pBt; + if( pBt ){ + Pager *pPager = sqlite3BtreePager(pBt); + totalUsed += sqlite3PagerMemUsed(pPager); + } + } + *pCurrent = totalUsed; + *pHighwater = 0; + break; + } default: { return SQLITE_ERROR; } diff --git a/src/test_malloc.c b/src/test_malloc.c index 5556cc1e6..d5f0a6df5 100644 --- a/src/test_malloc.c +++ b/src/test_malloc.c @@ -1287,6 +1287,7 @@ static int test_db_status( int op; } aOp[] = { { "SQLITE_DBSTATUS_LOOKASIDE_USED", SQLITE_DBSTATUS_LOOKASIDE_USED }, + { "SQLITE_DBSTATUS_CACHE_USED", SQLITE_DBSTATUS_CACHE_USED }, }; Tcl_Obj *pResult; if( objc!=4 ){ |