diff options
author | drh <drh@noemail.net> | 2017-05-31 17:30:08 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2017-05-31 17:30:08 +0000 |
commit | cdbb126be7335a05a5930b8d0fa775c7d3a86ef0 (patch) | |
tree | e5dd458652fc19a3a20f4c1571e3e7634cd61162 /src | |
parent | 6b37e0adc92057acbf743fd7103ce63d7270a226 (diff) | |
parent | 3528f6b62b8845354b11863bbe41858512e38d71 (diff) | |
download | sqlite-cdbb126be7335a05a5930b8d0fa775c7d3a86ef0.tar.gz sqlite-cdbb126be7335a05a5930b8d0fa775c7d3a86ef0.zip |
Add the SQLITE_STMTSTATUS_MEMUSED opcode to sqlite3_stmt_status()
for finding the heap memory usage by a single prepared statement.
FossilOrigin-Name: c26cf978eead1c9d265eddabaa421e7735b472fcf2792cd2bdeb0901bcf3fb44
Diffstat (limited to 'src')
-rw-r--r-- | src/sqlite.h.in | 7 | ||||
-rw-r--r-- | src/vdbeapi.c | 15 |
2 files changed, 20 insertions, 2 deletions
diff --git a/src/sqlite.h.in b/src/sqlite.h.in index d836e9705..06445d444 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -7133,6 +7133,12 @@ int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg); ** used as a proxy for the total work done by the prepared statement. ** If the number of virtual machine operations exceeds 2147483647 ** then the value returned by this statement status code is undefined. +** +** [[SQLITE_STMTSTATUS_MEMUSED]] <dt>SQLITE_STMTSTATUS_MEMUSED</dt> +** <dd>^This is the approximate number of bytes of heap memory +** used to store the prepared statement. ^This value is not actually +** a counter, and so the resetFlg parameter to sqlite3_stmt_status() +** is ignored when the opcode is SQLITE_STMTSTATUS_MEMUSED. ** </dd> ** </dl> */ @@ -7140,6 +7146,7 @@ int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg); #define SQLITE_STMTSTATUS_SORT 2 #define SQLITE_STMTSTATUS_AUTOINDEX 3 #define SQLITE_STMTSTATUS_VM_STEP 4 +#define SQLITE_STMTSTATUS_MEMUSED 5 /* ** CAPI3REF: Custom Page Cache Object diff --git a/src/vdbeapi.c b/src/vdbeapi.c index 3e439e3e8..93063dc60 100644 --- a/src/vdbeapi.c +++ b/src/vdbeapi.c @@ -1613,8 +1613,19 @@ int sqlite3_stmt_status(sqlite3_stmt *pStmt, int op, int resetFlag){ return 0; } #endif - v = pVdbe->aCounter[op]; - if( resetFlag ) pVdbe->aCounter[op] = 0; + if( op==SQLITE_STMTSTATUS_MEMUSED ){ + sqlite3 *db = pVdbe->db; + sqlite3_mutex_enter(db->mutex); + v = 0; + db->pnBytesFreed = (int*)&v; + sqlite3VdbeClearObject(db, pVdbe); + sqlite3DbFree(db, pVdbe); + db->pnBytesFreed = 0; + sqlite3_mutex_leave(db->mutex); + }else{ + v = pVdbe->aCounter[op]; + if( resetFlag ) pVdbe->aCounter[op] = 0; + } return (int)v; } |