mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-07 02:42:48 +03:00
Enhance the sqlite3_stmt_scanstatus() API and add sqlite3_stmt_scanstatus_v2(). For creation of easier to read query performance reports.
FossilOrigin-Name: 55800833645739efeddcacef464c623931cb6aeb43f4219b4e4faf473c25c8bb
This commit is contained in:
55
src/vdbe.c
55
src/vdbe.c
@@ -617,7 +617,6 @@ void sqlite3VdbeRegisterDump(Vdbe *v){
|
||||
# define REGISTER_TRACE(R,M)
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef NDEBUG
|
||||
/*
|
||||
** This function is only called from within an assert() expression. It
|
||||
@@ -707,10 +706,8 @@ int sqlite3VdbeExec(
|
||||
){
|
||||
Op *aOp = p->aOp; /* Copy of p->aOp */
|
||||
Op *pOp = aOp; /* Current operation */
|
||||
#if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
|
||||
Op *pOrigOp; /* Value of pOp at the top of the loop */
|
||||
#endif
|
||||
#ifdef SQLITE_DEBUG
|
||||
Op *pOrigOp; /* Value of pOp at the top of the loop */
|
||||
int nExtraDelete = 0; /* Verifies FORDELETE and AUXDELETE flags */
|
||||
#endif
|
||||
int rc = SQLITE_OK; /* Value to return */
|
||||
@@ -727,8 +724,8 @@ int sqlite3VdbeExec(
|
||||
Mem *pIn2 = 0; /* 2nd input operand */
|
||||
Mem *pIn3 = 0; /* 3rd input operand */
|
||||
Mem *pOut = 0; /* Output operand */
|
||||
#ifdef VDBE_PROFILE
|
||||
u64 start; /* CPU clock count at start of opcode */
|
||||
#if defined(SQLITE_ENABLE_STMT_SCANSTATUS) || defined(VDBE_PROFILE)
|
||||
u64 *pnCycle = 0;
|
||||
#endif
|
||||
/*** INSERT STACK UNION HERE ***/
|
||||
|
||||
@@ -791,12 +788,17 @@ int sqlite3VdbeExec(
|
||||
assert( rc==SQLITE_OK );
|
||||
|
||||
assert( pOp>=aOp && pOp<&aOp[p->nOp]);
|
||||
#ifdef VDBE_PROFILE
|
||||
start = sqlite3NProfileCnt ? sqlite3NProfileCnt : sqlite3Hwtime();
|
||||
#endif
|
||||
nVmStep++;
|
||||
#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
|
||||
if( p->anExec ) p->anExec[(int)(pOp-aOp)]++;
|
||||
#if defined(SQLITE_ENABLE_STMT_SCANSTATUS) || defined(VDBE_PROFILE)
|
||||
if( p->anExec ){
|
||||
assert( p->anExec && p->anCycle );
|
||||
p->anExec[(int)(pOp-aOp)]++;
|
||||
pnCycle = &p->anCycle[pOp-aOp];
|
||||
# ifdef VDBE_PROFILE
|
||||
if( sqlite3NProfileCnt==0 )
|
||||
# endif
|
||||
*pnCycle -= sqlite3Hwtime();
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Only allow tracing if SQLITE_DEBUG is defined.
|
||||
@@ -858,7 +860,7 @@ int sqlite3VdbeExec(
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
|
||||
#ifdef SQLITE_DEBUG
|
||||
pOrigOp = pOp;
|
||||
#endif
|
||||
|
||||
@@ -7150,8 +7152,9 @@ case OP_Program: { /* jump */
|
||||
pFrame->aOp = p->aOp;
|
||||
pFrame->nOp = p->nOp;
|
||||
pFrame->token = pProgram->token;
|
||||
#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
|
||||
#if defined(SQLITE_ENABLE_STMT_SCANSTATUS) || defined(VDBE_PROFILE)
|
||||
pFrame->anExec = p->anExec;
|
||||
pFrame->anCycle = p->anCycle;
|
||||
#endif
|
||||
#ifdef SQLITE_DEBUG
|
||||
pFrame->iFrameMagic = SQLITE_FRAME_MAGIC;
|
||||
@@ -7189,8 +7192,9 @@ case OP_Program: { /* jump */
|
||||
memset(pFrame->aOnce, 0, (pProgram->nOp + 7)/8);
|
||||
p->aOp = aOp = pProgram->aOp;
|
||||
p->nOp = pProgram->nOp;
|
||||
#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
|
||||
#if defined(SQLITE_ENABLE_STMT_SCANSTATUS) || defined(VDBE_PROFILE)
|
||||
p->anExec = 0;
|
||||
p->anCycle = 0;
|
||||
#endif
|
||||
#ifdef SQLITE_DEBUG
|
||||
/* Verify that second and subsequent executions of the same trigger do not
|
||||
@@ -8727,11 +8731,16 @@ default: { /* This is really OP_Noop, OP_Explain */
|
||||
*****************************************************************************/
|
||||
}
|
||||
|
||||
#ifdef VDBE_PROFILE
|
||||
{
|
||||
u64 endTime = sqlite3NProfileCnt ? sqlite3NProfileCnt : sqlite3Hwtime();
|
||||
if( endTime>start ) pOrigOp->cycles += endTime - start;
|
||||
pOrigOp->cnt++;
|
||||
#if defined(VDBE_PROFILE)
|
||||
assert( pnCycle );
|
||||
if( pnCycle ){
|
||||
*pnCycle += sqlite3NProfileCnt ? sqlite3NProfileCnt : sqlite3Hwtime();
|
||||
pnCycle = 0;
|
||||
}
|
||||
#elif defined(SQLITE_ENABLE_STMT_SCANSTATUS)
|
||||
if( pnCycle ){
|
||||
*pnCycle += sqlite3Hwtime();
|
||||
pnCycle = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -8808,6 +8817,14 @@ abort_due_to_error:
|
||||
** release the mutexes on btrees that were acquired at the
|
||||
** top. */
|
||||
vdbe_return:
|
||||
#if defined(VDBE_PROFILE)
|
||||
if( pnCycle ){
|
||||
*pnCycle += sqlite3NProfileCnt ? sqlite3NProfileCnt : sqlite3Hwtime();
|
||||
}
|
||||
#elif defined(SQLITE_ENABLE_STMT_SCANSTATUS)
|
||||
if( pnCycle ) *pnCycle += sqlite3Hwtime();
|
||||
#endif
|
||||
|
||||
#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
|
||||
while( nVmStep>=nProgressLimit && db->xProgress!=0 ){
|
||||
nProgressLimit += db->nProgressOps;
|
||||
|
Reference in New Issue
Block a user