Add the SQLITE_DBSTATUS_PROPORTIONAL_CACHE_USED sqlite3_db_status() parameter.

FossilOrigin-Name: 118321c8b9d88b8f439c952436f42838c3fc80cb
This commit is contained in:
dan 2016-07-06 10:12:02 +00:00
parent 50687436f7
commit 272989b44d
8 changed files with 88 additions and 16 deletions

View File

@ -1,5 +1,5 @@
C Fix\sa\smemory\sleak\sin\srecently\sadded\stest\scode.
D 2016-07-06T09:19:14.702
C Add\sthe\sSQLITE_DBSTATUS_PROPORTIONAL_CACHE_USED\ssqlite3_db_status()\sparameter.
D 2016-07-06T10:12:02.240
F Makefile.in 6c20d44f72d4564f11652b26291a214c8367e5db
F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
F Makefile.msc d66d0395c38571aab3804f8db0fa20707ae4609a
@ -327,8 +327,8 @@ F src/auth.c b56c78ebe40a2110fd361379f7e8162d23f92240
F src/backup.c 6df65fdd569c901a418887a1a76f82ec35044556
F src/bitvec.c 3ee4c8b2c94ed3a7377256e18199e6ff5cf33f63
F src/btmutex.c bc87dd3b062cc26edfe79918de2200ccb8d41e73
F src/btree.c 0621247619df15790f7ed5f14926cfb3925c10b1
F src/btree.h 2107a2630e02c8cba58bb12ce14e731e734ea29c
F src/btree.c dc4e5f3e95fd57b610422e36e0913662ecd6814c
F src/btree.h aee84823bb383d6ae3728b068f9130d2b36b71eb
F src/btreeInt.h c18b7d2a3494695133e4e60ee36061d37f45d9a5
F src/build.c d1fdfd7ab8f5447e494ef15825973bf0719527c6
F src/callback.c 2e76147783386374bf01b227f752c81ec872d730
@ -385,12 +385,12 @@ F src/resolve.c cca3aa77b95706df5d635a2141a4d1de60ae6598
F src/rowset.c 7b7e7e479212e65b723bf40128c7b36dc5afdfac
F src/select.c f3c6e9065fb34f6a23af27ec7f1f717ffbfc2ee4
F src/shell.c 14ff7f660530a52b117d110ba3390b7b2eb719b6
F src/sqlite.h.in 5f8113dbec74c6c093ead9930afb8c9fbd9f643d
F src/sqlite.h.in 801a34f86508662fbfc8e014f03ccf0c8bef0b4c
F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
F src/sqlite3ext.h 98f72cbfe00169c39089115427d06ea05fe4b4a2
F src/sqliteInt.h 2ac73e9fdd138f4607139d9bd6a1e6dcd01837dc
F src/sqliteLimit.h c0373387c287c8d0932510b5547ecde31b5da247
F src/status.c 70912d7be68e9e2dbc4010c93d344af61d4c59ba
F src/status.c d92daea3bb48023da57931719f2a2784f5487c0b
F src/table.c 5226df15ab9179b9ed558d89575ea0ce37b03fc9
F src/tclsqlite.c 25fbbbb97f76dbfd113153fb63f52d7ecfac5dd0
F src/test1.c 08faa045c45b1d3f62c28c93cae955f518317f68
@ -419,7 +419,7 @@ F src/test_intarray.c 870124b95ec4c645d4eb84f15efb7133528fb1a5
F src/test_intarray.h 9dc57417fb65bc7835cc18548852cc08cc062202
F src/test_journal.c d3b83f2bcb7792c709e57abddc456a2b1818643a
F src/test_loadext.c 337056bae59f80b9eb00ba82088b39d0f4fe6dfd
F src/test_malloc.c 94c18e88d6df6d471a0d04ddb809f833d1739950
F src/test_malloc.c 20954ab49e09be3433c8d2fd7a8bd0a0f1c76de7
F src/test_multiplex.c eafc567ebe162e36f17b5062285dfe90461cf8e9
F src/test_multiplex.h c08e4e8f8651f0c5e0509b138ff4d5b43ed1f5d3
F src/test_mutex.c dbdfaff8580071f2212a0deae3325a93a737819c
@ -621,7 +621,7 @@ F test/ctime.test 0b995accd44a52914bd4744d5c1b6e1a56c7897c
F test/cursorhint.test 7bc346788390475e77a345da2b92270d04d35856
F test/cursorhint2.test 2b45341d32d1aae9991a00ef31ebca339b274255
F test/date.test 984ac1e3e5e031386866f034006148d3972b4a65
F test/dbstatus.test 8de104bb5606f19537d23cd553b41349b5ab1204
F test/dbstatus.test c0c8752043074ab6479d2560341ae02f072ad3b9
F test/dbstatus2.test e93ab03bfae6d62d4d935f20de928c19ca0ed0ab
F test/default.test 0cb49b1c315a0d81c81d775e407f66906a2a604d
F test/delete.test e1bcdf8926234e27aac24b346ad83d3329ec8b6f
@ -1504,7 +1504,10 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P 2683b375ad1291172fdb47d94e16fcf869c78c8a
R bad3fed306e6177658099344318135b4
P 724e4cdc25fc80b8face57b3398cd338994fb23c
R 266d0a5d75bc1363b05e057e04a42c8c
T *branch * dbstatus-prop-cache-used
T *sym-dbstatus-prop-cache-used *
T -sym-trunk *
U dan
Z b779329b8bc265169140036a21a84f9f
Z d4bd876af7d67d4b270c7d6acc73f5f1

View File

@ -1 +1 @@
724e4cdc25fc80b8face57b3398cd338994fb23c
118321c8b9d88b8f439c952436f42838c3fc80cb

View File

@ -2337,9 +2337,9 @@ int sqlite3BtreeOpen(
#if !defined(SQLITE_OMIT_SHARED_CACHE) && !defined(SQLITE_OMIT_DISKIO)
/* Add the new BtShared object to the linked list sharable BtShareds.
*/
pBt->nRef = 1;
if( p->sharable ){
MUTEX_LOGIC( sqlite3_mutex *mutexShared; )
pBt->nRef = 1;
MUTEX_LOGIC( mutexShared = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);)
if( SQLITE_THREADSAFE && sqlite3GlobalConfig.bCoreMutex ){
pBt->mutex = sqlite3MutexAlloc(SQLITE_MUTEX_FAST);
@ -2410,6 +2410,7 @@ btree_open_out:
assert( sqlite3_mutex_held(mutexOpen) );
sqlite3_mutex_leave(mutexOpen);
}
assert( rc!=SQLITE_OK || sqlite3BtreeConnectionCount(*ppBtree)>0 );
return rc;
}
@ -9698,4 +9699,14 @@ int sqlite3HeaderSizeBtree(void){ return ROUND8(sizeof(MemPage)); }
int sqlite3BtreeSharable(Btree *p){
return p->sharable;
}
/*
** Return the number of connections to the BtShared object accessed by
** the Btree handle passed as the only argument. For private caches
** this is always 1. For shared caches it may be 1 or greater.
*/
int sqlite3BtreeConnectionCount(Btree *p){
testcase( p->sharable );
return p->pBt->nRef;
}
#endif

View File

@ -328,11 +328,13 @@ void sqlite3BtreeCursorList(Btree*);
void sqlite3BtreeEnterAll(sqlite3*);
int sqlite3BtreeSharable(Btree*);
void sqlite3BtreeEnterCursor(BtCursor*);
int sqlite3BtreeConnectionCount(Btree*);
#else
# define sqlite3BtreeEnter(X)
# define sqlite3BtreeEnterAll(X)
# define sqlite3BtreeSharable(X) 0
# define sqlite3BtreeEnterCursor(X)
# define sqlite3BtreeConnectionCount(X) 1
#endif
#if !defined(SQLITE_OMIT_SHARED_CACHE) && SQLITE_THREADSAFE

View File

@ -6765,6 +6765,18 @@ int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg);
** memory used by all pager caches associated with the database connection.)^
** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0.
**
** [[SQLITE_DBSTATUS_PROPORTIONAL_CACHE_USED]]
** ^(<dt>SQLITE_DBSTATUS_PROPORTIONAL_CACHE_USED</dt>
** <dd>This parameter is similar to DBSTATUS_CACHE_USED, except that if a
** pager cache is shared between two or more connections the bytes of heap
** memory used by that pager cache is divided evenly between the attached
** connections.)^ In other words, if none of the pager caches associated
** with the database connection are shared, this request returns the same
** value as DBSTATUS_CACHE_USED. Or, if one or more or the pager caches are
** shared, the value returned by this call will be smaller than that returned
** by DBSTATUS_CACHE_USED. ^The highwater mark associated with
** SQLITE_DBSTATUS_PROPORTIONAL_CACHE_USED is always 0.
**
** [[SQLITE_DBSTATUS_SCHEMA_USED]] ^(<dt>SQLITE_DBSTATUS_SCHEMA_USED</dt>
** <dd>This parameter returns the approximate number of bytes of heap
** memory used to store the schema for all databases associated
@ -6822,7 +6834,8 @@ int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg);
#define SQLITE_DBSTATUS_CACHE_MISS 8
#define SQLITE_DBSTATUS_CACHE_WRITE 9
#define SQLITE_DBSTATUS_DEFERRED_FKS 10
#define SQLITE_DBSTATUS_MAX 10 /* Largest defined DBSTATUS */
#define SQLITE_DBSTATUS_PROPORTIONAL_CACHE_USED 11
#define SQLITE_DBSTATUS_MAX 11 /* Largest defined DBSTATUS */
/*

View File

@ -219,6 +219,7 @@ int sqlite3_db_status(
** by all pagers associated with the given database connection. The
** highwater mark is meaningless and is returned as zero.
*/
case SQLITE_DBSTATUS_PROPORTIONAL_CACHE_USED:
case SQLITE_DBSTATUS_CACHE_USED: {
int totalUsed = 0;
int i;
@ -227,7 +228,11 @@ int sqlite3_db_status(
Btree *pBt = db->aDb[i].pBt;
if( pBt ){
Pager *pPager = sqlite3BtreePager(pBt);
totalUsed += sqlite3PagerMemUsed(pPager);
int nByte = sqlite3PagerMemUsed(pPager);
if( op==SQLITE_DBSTATUS_PROPORTIONAL_CACHE_USED ){
nByte = nByte / sqlite3BtreeConnectionCount(pBt);
}
totalUsed += nByte;
}
}
sqlite3BtreeLeaveAll(db);

View File

@ -1417,7 +1417,8 @@ static int test_db_status(
{ "CACHE_HIT", SQLITE_DBSTATUS_CACHE_HIT },
{ "CACHE_MISS", SQLITE_DBSTATUS_CACHE_MISS },
{ "CACHE_WRITE", SQLITE_DBSTATUS_CACHE_WRITE },
{ "DEFERRED_FKS", SQLITE_DBSTATUS_DEFERRED_FKS }
{ "DEFERRED_FKS", SQLITE_DBSTATUS_DEFERRED_FKS },
{ "PROPORTIONAL_CACHE_USED", SQLITE_DBSTATUS_PROPORTIONAL_CACHE_USED },
};
Tcl_Obj *pResult;
if( objc!=4 ){

View File

@ -14,6 +14,7 @@
set testdir [file dirname $argv0]
source $testdir/tester.tcl
set testprefix dbstatus
ifcapable !compound {
finish_test
@ -24,6 +25,7 @@ ifcapable !compound {
db close
sqlite3_shutdown
sqlite3_config_memstatus 1
sqlite3_config_uri 1
sqlite3_initialize
sqlite3 db test.db
@ -377,4 +379,39 @@ foreach ::lookaside_buffer_size {0 64 120} {
}
}
#-------------------------------------------------------------------------
# The following tests focus on DBSTATUS_PROPORTIONAL_CACHE_USED
#
ifcapable shared_cache {
proc do_cacheused_test {tn db res} {
set cu [sqlite3_db_status $db SQLITE_DBSTATUS_CACHE_USED 0]
set pcu [sqlite3_db_status $db SQLITE_DBSTATUS_PROPORTIONAL_CACHE_USED 0]
set cu [lindex $cu 1]
set pcu [lindex $pcu 1]
uplevel [list do_test $tn [list list $cu $pcu] [list {*}$res]]
}
reset_db
sqlite3 db file:test.db?cache=shared
do_execsql_test 4.0 {
CREATE TABLE t1(a, b, c);
INSERT INTO t1 VALUES(1, 2, 3);
}
do_cacheused_test 4.0.1 db { 4568 4568 }
do_execsql_test 4.1 {
CREATE TEMP TABLE tt(a, b, c);
INSERT INTO tt VALUES(1, 2, 3);
}
do_cacheused_test 4.1.1 db { 9000 9000 }
sqlite3 db2 file:test.db?cache=shared
do_cacheused_test 4.2.1 db2 { 4568 2284 }
do_cacheused_test 4.2.2 db { 9000 6716 }
db close
do_cacheused_test 4.2.3 db2 { 4568 4568 }
sqlite3 db file:test.db?cache=shared
do_cacheused_test 4.2.4 db2 { 4568 2284 }
db2 close
}
finish_test