Add the ".scanstats on" command to the shell tool. Executing this command causes the shell tool to print values from sqlite3_stmt_scanstatus() after each query is run.

FossilOrigin-Name: 7974c0ed10ffdc960a43fed89845c2bed428958d
This commit is contained in:
dan 2014-11-05 09:07:28 +00:00
parent 547fb61807
commit 8d1edb92c4
3 changed files with 62 additions and 8 deletions

View File

@ -1,5 +1,5 @@
C Improved\soutput\sformatting\sfor\sthe\sshowstat4\stool.
D 2014-11-04T21:38:45.383
C Add\sthe\s".scanstats\son"\scommand\sto\sthe\sshell\stool.\sExecuting\sthis\scommand\scauses\sthe\sshell\stool\sto\sprint\svalues\sfrom\ssqlite3_stmt_scanstatus()\safter\seach\squery\sis\srun.
D 2014-11-05T09:07:28.365
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in cf57f673d77606ab0f2d9627ca52a9ba1464146a
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@ -228,7 +228,7 @@ F src/random.c ba2679f80ec82c4190062d756f22d0c358180696
F src/resolve.c 4965007d6497b6a4d7a6d98751cc39712885f952
F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e
F src/select.c 428165951748151e87a15295b7357221433e311b
F src/shell.c 282f8f5278e0c78eb442217531172ec9e1538796
F src/shell.c 5ad1eb4dfcd7a57e15825207a9bd559415bf34b1
F src/sqlite.h.in 6e9af739d79f0bea2584b70fb1c54d3bb1a2eab6
F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad
F src/sqlite3ext.h 17d487c3c91b0b8c584a32fbeb393f6f795eea7d
@ -1211,7 +1211,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32
F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
P d423349d2cd8bc7e04f3d90ca7bab11e1ad86e25
R 3d8e834a0bd7bfcb019dc53478b58f7b
U drh
Z 0a79c8f46f24bb92a10190eb30b27d6d
P 7df82c46da437bc743576358c25e758280067df8
R f4931dcb1177b970d566df3dbaa382ec
U dan
Z 44baa22d0450fc9fcacf5946d93d71c5

View File

@ -1 +1 @@
7df82c46da437bc743576358c25e758280067df8
7974c0ed10ffdc960a43fed89845c2bed428958d

View File

@ -457,6 +457,7 @@ struct ShellState {
int echoOn; /* True to echo input commands */
int autoEQP; /* Run EXPLAIN QUERY PLAN prior to seach SQL stmt */
int statsOn; /* True to display memory stats before each finalize */
int scanstatsOn; /* True to display scan stats before each finalize */
int outCount; /* Revert to stdout when reaching zero */
int cnt; /* Number of records displayed so far */
FILE *out; /* Write results here */
@ -1185,6 +1186,42 @@ static int display_stats(
return 0;
}
/*
** Display scan stats.
*/
static void display_scanstats(
sqlite3 *db, /* Database to query */
ShellState *pArg /* Pointer to ShellState */
){
#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
int i;
fprintf(pArg->out, "-------- scanstats --------\n");
for(i=0; 1; i++){
sqlite3_stmt *p = pArg->pStmt;
sqlite3_int64 nEst, nLoop, nVisit;
const char *zExplain;
if( sqlite3_stmt_scanstatus(p, i, SQLITE_SCANSTAT_NLOOP, (void*)&nLoop) ){
break;
}
sqlite3_stmt_scanstatus(p, i, SQLITE_SCANSTAT_NVISIT, (void*)&nVisit);
sqlite3_stmt_scanstatus(p, i, SQLITE_SCANSTAT_EST, (void*)&nEst);
sqlite3_stmt_scanstatus(p, i, SQLITE_SCANSTAT_EXPLAIN, (void*)&zExplain);
fprintf(pArg->out, "Loop %d: \"%s\"\n", i, zExplain);
fprintf(pArg->out, " nLoop=%-8lld nVisit=%-8lld nEst=%-8lld\n",
nLoop, nVisit, nEst
);
}
#else
fprintf(pArg->out, "-------- scanstats --------\n");
fprintf(pArg->out,
"sqlite3_stmt_scanstatus() unavailable - "
"rebuild with SQLITE_ENABLE_STMT_SCANSTATUS\n"
);
#endif
fprintf(pArg->out, "---------------------------\n");
}
/*
** Parameter azArray points to a zero-terminated array of strings. zStr
** points to a single nul-terminated string. Return non-zero if zStr
@ -1423,6 +1460,11 @@ static int shell_exec(
display_stats(db, pArg, 0);
}
/* print loop-counters if required */
if( pArg && pArg->scanstatsOn ){
display_scanstats(db, pArg);
}
/* Finalize the statement just executed. If this fails, save a
** copy of the error message. Otherwise, set zSql to point to the
** next statement to execute. */
@ -3014,6 +3056,16 @@ static int do_meta_command(char *zLine, ShellState *p){
sqlite3_close(pSrc);
}else
if( c=='s' && strncmp(azArg[0], "scanstats", n)==0 ){
if( nArg==2 ){
p->scanstatsOn = booleanValue(azArg[1]);
}else{
fprintf(stderr, "Usage: .scanstats on|off\n");
rc = 1;
}
}else
if( c=='s' && strncmp(azArg[0], "schema", n)==0 ){
ShellState data;
char *zErrMsg = 0;
@ -4140,6 +4192,8 @@ int main(int argc, char **argv){
data.autoEQP = 1;
}else if( strcmp(z,"-stats")==0 ){
data.statsOn = 1;
}else if( strcmp(z,"-scanstats")==0 ){
data.scanstatsOn = 1;
}else if( strcmp(z,"-bail")==0 ){
bail_on_error = 1;
}else if( strcmp(z,"-version")==0 ){