OLD | NEW |
1 /* | 1 /* |
2 ** A program for performance testing. | 2 ** A program for performance testing. |
3 ** | 3 ** |
4 ** The available command-line options are described below: | 4 ** The available command-line options are described below: |
5 */ | 5 */ |
6 static const char zHelp[] = | 6 static const char zHelp[] = |
7 "Usage: %s [--options] DATABASE\n" | 7 "Usage: %s [--options] DATABASE\n" |
8 "Options:\n" | 8 "Options:\n" |
9 " --autovacuum Enable AUTOVACUUM mode\n" | 9 " --autovacuum Enable AUTOVACUUM mode\n" |
10 " --cachesize N Set the cache size to N\n" | 10 " --cachesize N Set the cache size to N\n" |
11 " --exclusive Enable locking_mode=EXCLUSIVE\n" | 11 " --exclusive Enable locking_mode=EXCLUSIVE\n" |
12 " --explain Like --sqlonly but with added EXPLAIN keywords\n" | 12 " --explain Like --sqlonly but with added EXPLAIN keywords\n" |
13 " --heap SZ MIN Memory allocator uses SZ bytes & min allocation MIN\n" | 13 " --heap SZ MIN Memory allocator uses SZ bytes & min allocation MIN\n" |
14 " --incrvacuum Enable incremenatal vacuum mode\n" | 14 " --incrvacuum Enable incremenatal vacuum mode\n" |
15 " --journalmode M Set the journal_mode to MODE\n" | 15 " --journal M Set the journal_mode to M\n" |
16 " --key KEY Set the encryption key to KEY\n" | 16 " --key KEY Set the encryption key to KEY\n" |
17 " --lookaside N SZ Configure lookaside for N slots of SZ bytes each\n" | 17 " --lookaside N SZ Configure lookaside for N slots of SZ bytes each\n" |
| 18 " --multithread Set multithreaded mode\n" |
| 19 " --nomemstat Disable memory statistics\n" |
18 " --nosync Set PRAGMA synchronous=OFF\n" | 20 " --nosync Set PRAGMA synchronous=OFF\n" |
19 " --notnull Add NOT NULL constraints to table columns\n" | 21 " --notnull Add NOT NULL constraints to table columns\n" |
20 " --pagesize N Set the page size to N\n" | 22 " --pagesize N Set the page size to N\n" |
21 " --pcache N SZ Configure N pages of pagecache each of size SZ bytes\n" | 23 " --pcache N SZ Configure N pages of pagecache each of size SZ bytes\n" |
22 " --primarykey Use PRIMARY KEY instead of UNIQUE where appropriate\n" | 24 " --primarykey Use PRIMARY KEY instead of UNIQUE where appropriate\n" |
23 " --reprepare Reprepare each statement upon every invocation\n" | 25 " --reprepare Reprepare each statement upon every invocation\n" |
24 " --scratch N SZ Configure scratch memory for N slots of SZ bytes each\n
" | 26 " --scratch N SZ Configure scratch memory for N slots of SZ bytes each\n
" |
| 27 " --serialized Set serialized threading mode\n" |
| 28 " --singlethread Set single-threaded mode - disables all mutexing\n" |
25 " --sqlonly No-op. Only show the SQL that would have been run.\n" | 29 " --sqlonly No-op. Only show the SQL that would have been run.\n" |
| 30 " --shrink-memory Invoke sqlite3_db_release_memory() frequently.\n" |
26 " --size N Relative test size. Default=100\n" | 31 " --size N Relative test size. Default=100\n" |
27 " --stats Show statistics at the end\n" | 32 " --stats Show statistics at the end\n" |
28 " --testset T Run test-set T\n" | 33 " --testset T Run test-set T\n" |
29 " --trace Turn on SQL tracing\n" | 34 " --trace Turn on SQL tracing\n" |
30 " --threads N Use up to N threads for sorting\n" | 35 " --threads N Use up to N threads for sorting\n" |
31 " --utf16be Set text encoding to UTF-16BE\n" | 36 " --utf16be Set text encoding to UTF-16BE\n" |
32 " --utf16le Set text encoding to UTF-16LE\n" | 37 " --utf16le Set text encoding to UTF-16LE\n" |
33 " --verify Run additional verification steps.\n" | 38 " --verify Run additional verification steps.\n" |
34 " --without-rowid Use WITHOUT ROWID where appropriate\n" | 39 " --without-rowid Use WITHOUT ROWID where appropriate\n" |
35 ; | 40 ; |
36 | 41 |
37 | 42 |
38 #include "sqlite3.h" | 43 #include "sqlite3.h" |
39 #include <assert.h> | 44 #include <assert.h> |
40 #include <stdio.h> | 45 #include <stdio.h> |
41 #include <stdlib.h> | 46 #include <stdlib.h> |
42 #include <stdarg.h> | 47 #include <stdarg.h> |
43 #include <string.h> | 48 #include <string.h> |
44 #include <ctype.h> | 49 #include <ctype.h> |
| 50 #define ISSPACE(X) isspace((unsigned char)(X)) |
| 51 #define ISDIGIT(X) isdigit((unsigned char)(X)) |
| 52 |
| 53 #if SQLITE_VERSION_NUMBER<3005000 |
| 54 # define sqlite3_int64 sqlite_int64 |
| 55 #endif |
| 56 #ifdef SQLITE_ENABLE_RBU |
| 57 # include "sqlite3rbu.h" |
| 58 #endif |
45 | 59 |
46 /* All global state is held in this structure */ | 60 /* All global state is held in this structure */ |
47 static struct Global { | 61 static struct Global { |
48 sqlite3 *db; /* The open database connection */ | 62 sqlite3 *db; /* The open database connection */ |
49 sqlite3_stmt *pStmt; /* Current SQL statement */ | 63 sqlite3_stmt *pStmt; /* Current SQL statement */ |
50 sqlite3_int64 iStart; /* Start-time for the current test */ | 64 sqlite3_int64 iStart; /* Start-time for the current test */ |
51 sqlite3_int64 iTotal; /* Total time */ | 65 sqlite3_int64 iTotal; /* Total time */ |
52 int bWithoutRowid; /* True for --without-rowid */ | 66 int bWithoutRowid; /* True for --without-rowid */ |
53 int bReprepare; /* True to reprepare the SQL on each rerun */ | 67 int bReprepare; /* True to reprepare the SQL on each rerun */ |
54 int bSqlOnly; /* True to print the SQL once only */ | 68 int bSqlOnly; /* True to print the SQL once only */ |
55 int bExplain; /* Print SQL with EXPLAIN prefix */ | 69 int bExplain; /* Print SQL with EXPLAIN prefix */ |
56 int bVerify; /* Try to verify that results are correct */ | 70 int bVerify; /* Try to verify that results are correct */ |
| 71 int bMemShrink; /* Call sqlite3_db_release_memory() often */ |
57 int szTest; /* Scale factor for test iterations */ | 72 int szTest; /* Scale factor for test iterations */ |
58 const char *zWR; /* Might be WITHOUT ROWID */ | 73 const char *zWR; /* Might be WITHOUT ROWID */ |
59 const char *zNN; /* Might be NOT NULL */ | 74 const char *zNN; /* Might be NOT NULL */ |
60 const char *zPK; /* Might be UNIQUE or PRIMARY KEY */ | 75 const char *zPK; /* Might be UNIQUE or PRIMARY KEY */ |
61 unsigned int x, y; /* Pseudo-random number generator state */ | 76 unsigned int x, y; /* Pseudo-random number generator state */ |
62 int nResult; /* Size of the current result */ | 77 int nResult; /* Size of the current result */ |
63 char zResult[3000]; /* Text of the current result */ | 78 char zResult[3000]; /* Text of the current result */ |
64 } g; | 79 } g; |
65 | 80 |
66 | 81 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 v *= aMult[i].iMult; | 147 v *= aMult[i].iMult; |
133 break; | 148 break; |
134 } | 149 } |
135 } | 150 } |
136 if( v>0x7fffffff ) fatal_error("parameter too large - max 2147483648"); | 151 if( v>0x7fffffff ) fatal_error("parameter too large - max 2147483648"); |
137 return (int)(isNeg? -v : v); | 152 return (int)(isNeg? -v : v); |
138 } | 153 } |
139 | 154 |
140 /* Return the current wall-clock time, in milliseconds */ | 155 /* Return the current wall-clock time, in milliseconds */ |
141 sqlite3_int64 speedtest1_timestamp(void){ | 156 sqlite3_int64 speedtest1_timestamp(void){ |
| 157 #if SQLITE_VERSION_NUMBER<3005000 |
| 158 return 0; |
| 159 #else |
142 static sqlite3_vfs *clockVfs = 0; | 160 static sqlite3_vfs *clockVfs = 0; |
143 sqlite3_int64 t; | 161 sqlite3_int64 t; |
144 if( clockVfs==0 ) clockVfs = sqlite3_vfs_find(0); | 162 if( clockVfs==0 ) clockVfs = sqlite3_vfs_find(0); |
145 #if SQLITE_VERSION_NUMBER>=3007000 | 163 #if SQLITE_VERSION_NUMBER>=3007000 |
146 if( clockVfs->iVersion>=2 && clockVfs->xCurrentTimeInt64!=0 ){ | 164 if( clockVfs->iVersion>=2 && clockVfs->xCurrentTimeInt64!=0 ){ |
147 clockVfs->xCurrentTimeInt64(clockVfs, &t); | 165 clockVfs->xCurrentTimeInt64(clockVfs, &t); |
148 }else | 166 }else |
149 #endif | 167 #endif |
150 { | 168 { |
151 double r; | 169 double r; |
152 clockVfs->xCurrentTime(clockVfs, &r); | 170 clockVfs->xCurrentTime(clockVfs, &r); |
153 t = (sqlite3_int64)(r*86400000.0); | 171 t = (sqlite3_int64)(r*86400000.0); |
154 } | 172 } |
155 return t; | 173 return t; |
| 174 #endif |
156 } | 175 } |
157 | 176 |
158 /* Return a pseudo-random unsigned integer */ | 177 /* Return a pseudo-random unsigned integer */ |
159 unsigned int speedtest1_random(void){ | 178 unsigned int speedtest1_random(void){ |
160 g.x = (g.x>>1) ^ ((1+~(g.x&1)) & 0xd0000001); | 179 g.x = (g.x>>1) ^ ((1+~(g.x&1)) & 0xd0000001); |
161 g.y = g.y*1103515245 + 12345; | 180 g.y = g.y*1103515245 + 12345; |
162 return g.x ^ g.y; | 181 return g.x ^ g.y; |
163 } | 182 } |
164 | 183 |
165 /* Map the value in within the range of 1...limit into another | 184 /* Map the value in within the range of 1...limit into another |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 void speedtest1_final(void){ | 310 void speedtest1_final(void){ |
292 if( !g.bSqlOnly ){ | 311 if( !g.bSqlOnly ){ |
293 printf(" TOTAL%.*s %4d.%03ds\n", NAMEWIDTH-5, zDots, | 312 printf(" TOTAL%.*s %4d.%03ds\n", NAMEWIDTH-5, zDots, |
294 (int)(g.iTotal/1000), (int)(g.iTotal%1000)); | 313 (int)(g.iTotal/1000), (int)(g.iTotal%1000)); |
295 } | 314 } |
296 } | 315 } |
297 | 316 |
298 /* Print an SQL statement to standard output */ | 317 /* Print an SQL statement to standard output */ |
299 static void printSql(const char *zSql){ | 318 static void printSql(const char *zSql){ |
300 int n = (int)strlen(zSql); | 319 int n = (int)strlen(zSql); |
301 while( n>0 && (zSql[n-1]==';' || isspace(zSql[n-1])) ){ n--; } | 320 while( n>0 && (zSql[n-1]==';' || ISSPACE(zSql[n-1])) ){ n--; } |
302 if( g.bExplain ) printf("EXPLAIN "); | 321 if( g.bExplain ) printf("EXPLAIN "); |
303 printf("%.*s;\n", n, zSql); | 322 printf("%.*s;\n", n, zSql); |
304 if( g.bExplain | 323 if( g.bExplain |
305 #if SQLITE_VERSION_NUMBER>=3007010 | 324 #if SQLITE_VERSION_NUMBER>=3007017 |
306 && ( sqlite3_strglob("CREATE *", zSql)==0 | 325 && ( sqlite3_strglob("CREATE *", zSql)==0 |
307 || sqlite3_strglob("DROP *", zSql)==0 | 326 || sqlite3_strglob("DROP *", zSql)==0 |
308 || sqlite3_strglob("ALTER *", zSql)==0 | 327 || sqlite3_strglob("ALTER *", zSql)==0 |
309 ) | 328 ) |
310 #endif | 329 #endif |
311 ){ | 330 ){ |
312 printf("%.*s;\n", n, zSql); | 331 printf("%.*s;\n", n, zSql); |
313 } | 332 } |
314 } | 333 } |
315 | 334 |
| 335 /* Shrink memory used, if appropriate and if the SQLite version is capable |
| 336 ** of doing so. |
| 337 */ |
| 338 void speedtest1_shrink_memory(void){ |
| 339 #if SQLITE_VERSION_NUMBER>=3007010 |
| 340 if( g.bMemShrink ) sqlite3_db_release_memory(g.db); |
| 341 #endif |
| 342 } |
| 343 |
316 /* Run SQL */ | 344 /* Run SQL */ |
317 void speedtest1_exec(const char *zFormat, ...){ | 345 void speedtest1_exec(const char *zFormat, ...){ |
318 va_list ap; | 346 va_list ap; |
319 char *zSql; | 347 char *zSql; |
320 va_start(ap, zFormat); | 348 va_start(ap, zFormat); |
321 zSql = sqlite3_vmprintf(zFormat, ap); | 349 zSql = sqlite3_vmprintf(zFormat, ap); |
322 va_end(ap); | 350 va_end(ap); |
323 if( g.bSqlOnly ){ | 351 if( g.bSqlOnly ){ |
324 printSql(zSql); | 352 printSql(zSql); |
325 }else{ | 353 }else{ |
326 char *zErrMsg = 0; | 354 char *zErrMsg = 0; |
327 int rc = sqlite3_exec(g.db, zSql, 0, 0, &zErrMsg); | 355 int rc = sqlite3_exec(g.db, zSql, 0, 0, &zErrMsg); |
328 if( zErrMsg ) fatal_error("SQL error: %s\n%s\n", zErrMsg, zSql); | 356 if( zErrMsg ) fatal_error("SQL error: %s\n%s\n", zErrMsg, zSql); |
329 if( rc!=SQLITE_OK ) fatal_error("exec error: %s\n", sqlite3_errmsg(g.db)); | 357 if( rc!=SQLITE_OK ) fatal_error("exec error: %s\n", sqlite3_errmsg(g.db)); |
330 } | 358 } |
331 sqlite3_free(zSql); | 359 sqlite3_free(zSql); |
| 360 speedtest1_shrink_memory(); |
332 } | 361 } |
333 | 362 |
334 /* Prepare an SQL statement */ | 363 /* Prepare an SQL statement */ |
335 void speedtest1_prepare(const char *zFormat, ...){ | 364 void speedtest1_prepare(const char *zFormat, ...){ |
336 va_list ap; | 365 va_list ap; |
337 char *zSql; | 366 char *zSql; |
338 va_start(ap, zFormat); | 367 va_start(ap, zFormat); |
339 zSql = sqlite3_vmprintf(zFormat, ap); | 368 zSql = sqlite3_vmprintf(zFormat, ap); |
340 va_end(ap); | 369 va_end(ap); |
341 if( g.bSqlOnly ){ | 370 if( g.bSqlOnly ){ |
(...skipping 21 matching lines...) Expand all Loading... |
363 const char *z = (const char*)sqlite3_column_text(g.pStmt, i); | 392 const char *z = (const char*)sqlite3_column_text(g.pStmt, i); |
364 if( z==0 ) z = "nil"; | 393 if( z==0 ) z = "nil"; |
365 len = (int)strlen(z); | 394 len = (int)strlen(z); |
366 if( g.nResult+len<sizeof(g.zResult)-2 ){ | 395 if( g.nResult+len<sizeof(g.zResult)-2 ){ |
367 if( g.nResult>0 ) g.zResult[g.nResult++] = ' '; | 396 if( g.nResult>0 ) g.zResult[g.nResult++] = ' '; |
368 memcpy(g.zResult + g.nResult, z, len+1); | 397 memcpy(g.zResult + g.nResult, z, len+1); |
369 g.nResult += len; | 398 g.nResult += len; |
370 } | 399 } |
371 } | 400 } |
372 } | 401 } |
| 402 #if SQLITE_VERSION_NUMBER>=3006001 |
373 if( g.bReprepare ){ | 403 if( g.bReprepare ){ |
374 sqlite3_stmt *pNew; | 404 sqlite3_stmt *pNew; |
375 sqlite3_prepare_v2(g.db, sqlite3_sql(g.pStmt), -1, &pNew, 0); | 405 sqlite3_prepare_v2(g.db, sqlite3_sql(g.pStmt), -1, &pNew, 0); |
376 sqlite3_finalize(g.pStmt); | 406 sqlite3_finalize(g.pStmt); |
377 g.pStmt = pNew; | 407 g.pStmt = pNew; |
378 }else{ | 408 }else |
| 409 #endif |
| 410 { |
379 sqlite3_reset(g.pStmt); | 411 sqlite3_reset(g.pStmt); |
380 } | 412 } |
| 413 speedtest1_shrink_memory(); |
381 } | 414 } |
382 | 415 |
383 /* The sqlite3_trace() callback function */ | 416 /* The sqlite3_trace() callback function */ |
384 static void traceCallback(void *NotUsed, const char *zSql){ | 417 static void traceCallback(void *NotUsed, const char *zSql){ |
385 int n = (int)strlen(zSql); | 418 int n = (int)strlen(zSql); |
386 while( n>0 && (zSql[n-1]==';' || isspace(zSql[n-1])) ) n--; | 419 while( n>0 && (zSql[n-1]==';' || ISSPACE(zSql[n-1])) ) n--; |
387 fprintf(stderr,"%.*s;\n", n, zSql); | 420 fprintf(stderr,"%.*s;\n", n, zSql); |
388 } | 421 } |
389 | 422 |
390 /* Substitute random() function that gives the same random | 423 /* Substitute random() function that gives the same random |
391 ** sequence on each run, for repeatability. */ | 424 ** sequence on each run, for repeatability. */ |
392 static void randomFunc( | 425 static void randomFunc( |
393 sqlite3_context *context, | 426 sqlite3_context *context, |
394 int NotUsed, | 427 int NotUsed, |
395 sqlite3_value **NotUsed2 | 428 sqlite3_value **NotUsed2 |
396 ){ | 429 ){ |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
527 zNum[0] = '%'; | 560 zNum[0] = '%'; |
528 len = speedtest1_numbername(i, zNum+1, sizeof(zNum)-2); | 561 len = speedtest1_numbername(i, zNum+1, sizeof(zNum)-2); |
529 zNum[len] = '%'; | 562 zNum[len] = '%'; |
530 zNum[len+1] = 0; | 563 zNum[len+1] = 0; |
531 sqlite3_bind_text(g.pStmt, 1, zNum, len, SQLITE_STATIC); | 564 sqlite3_bind_text(g.pStmt, 1, zNum, len, SQLITE_STATIC); |
532 speedtest1_run(); | 565 speedtest1_run(); |
533 } | 566 } |
534 speedtest1_exec("COMMIT"); | 567 speedtest1_exec("COMMIT"); |
535 speedtest1_end_test(); | 568 speedtest1_end_test(); |
536 | 569 |
537 n = 10; //g.szTest/5; | 570 n = 10; /* g.szTest/5; */ |
538 speedtest1_begin_test(145, "%d SELECTS w/ORDER BY and LIMIT, unindexed", n); | 571 speedtest1_begin_test(145, "%d SELECTS w/ORDER BY and LIMIT, unindexed", n); |
539 speedtest1_exec("BEGIN"); | 572 speedtest1_exec("BEGIN"); |
540 speedtest1_prepare( | 573 speedtest1_prepare( |
541 "SELECT a, b, c FROM t1 WHERE c LIKE ?1\n" | 574 "SELECT a, b, c FROM t1 WHERE c LIKE ?1\n" |
542 " ORDER BY a LIMIT 10; -- %d times", n | 575 " ORDER BY a LIMIT 10; -- %d times", n |
543 ); | 576 ); |
544 for(i=1; i<=n; i++){ | 577 for(i=1; i<=n; i++){ |
545 x1 = speedtest1_random()%maxb; | 578 x1 = speedtest1_random()%maxb; |
546 zNum[0] = '%'; | 579 zNum[0] = '%'; |
547 len = speedtest1_numbername(i, zNum+1, sizeof(zNum)-2); | 580 len = speedtest1_numbername(i, zNum+1, sizeof(zNum)-2); |
(...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1139 int cacheSize = 0; /* Desired cache size. 0 means default */ | 1172 int cacheSize = 0; /* Desired cache size. 0 means default */ |
1140 int doExclusive = 0; /* True for --exclusive */ | 1173 int doExclusive = 0; /* True for --exclusive */ |
1141 int nHeap = 0, mnHeap = 0; /* Heap size from --heap */ | 1174 int nHeap = 0, mnHeap = 0; /* Heap size from --heap */ |
1142 int doIncrvac = 0; /* True for --incrvacuum */ | 1175 int doIncrvac = 0; /* True for --incrvacuum */ |
1143 const char *zJMode = 0; /* Journal mode */ | 1176 const char *zJMode = 0; /* Journal mode */ |
1144 const char *zKey = 0; /* Encryption key */ | 1177 const char *zKey = 0; /* Encryption key */ |
1145 int nLook = 0, szLook = 0; /* --lookaside configuration */ | 1178 int nLook = 0, szLook = 0; /* --lookaside configuration */ |
1146 int noSync = 0; /* True for --nosync */ | 1179 int noSync = 0; /* True for --nosync */ |
1147 int pageSize = 0; /* Desired page size. 0 means default */ | 1180 int pageSize = 0; /* Desired page size. 0 means default */ |
1148 int nPCache = 0, szPCache = 0;/* --pcache configuration */ | 1181 int nPCache = 0, szPCache = 0;/* --pcache configuration */ |
| 1182 int doPCache = 0; /* True if --pcache is seen */ |
1149 int nScratch = 0, szScratch=0;/* --scratch configuration */ | 1183 int nScratch = 0, szScratch=0;/* --scratch configuration */ |
1150 int showStats = 0; /* True for --stats */ | 1184 int showStats = 0; /* True for --stats */ |
1151 int nThread = 0; /* --threads value */ | 1185 int nThread = 0; /* --threads value */ |
1152 const char *zTSet = "main"; /* Which --testset torun */ | 1186 const char *zTSet = "main"; /* Which --testset torun */ |
1153 int doTrace = 0; /* True for --trace */ | 1187 int doTrace = 0; /* True for --trace */ |
1154 const char *zEncoding = 0; /* --utf16be or --utf16le */ | 1188 const char *zEncoding = 0; /* --utf16be or --utf16le */ |
1155 const char *zDbName = 0; /* Name of the test database */ | 1189 const char *zDbName = 0; /* Name of the test database */ |
1156 | 1190 |
1157 void *pHeap = 0; /* Allocated heap space */ | 1191 void *pHeap = 0; /* Allocated heap space */ |
1158 void *pLook = 0; /* Allocated lookaside space */ | 1192 void *pLook = 0; /* Allocated lookaside space */ |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1193 if( i>=argc-1 ) fatal_error("missing argument on %s\n", argv[i]); | 1227 if( i>=argc-1 ) fatal_error("missing argument on %s\n", argv[i]); |
1194 zJMode = argv[++i]; | 1228 zJMode = argv[++i]; |
1195 }else if( strcmp(z,"key")==0 ){ | 1229 }else if( strcmp(z,"key")==0 ){ |
1196 if( i>=argc-1 ) fatal_error("missing argument on %s\n", argv[i]); | 1230 if( i>=argc-1 ) fatal_error("missing argument on %s\n", argv[i]); |
1197 zKey = argv[++i]; | 1231 zKey = argv[++i]; |
1198 }else if( strcmp(z,"lookaside")==0 ){ | 1232 }else if( strcmp(z,"lookaside")==0 ){ |
1199 if( i>=argc-2 ) fatal_error("missing arguments on %s\n", argv[i]); | 1233 if( i>=argc-2 ) fatal_error("missing arguments on %s\n", argv[i]); |
1200 nLook = integerValue(argv[i+1]); | 1234 nLook = integerValue(argv[i+1]); |
1201 szLook = integerValue(argv[i+2]); | 1235 szLook = integerValue(argv[i+2]); |
1202 i += 2; | 1236 i += 2; |
| 1237 }else if( strcmp(z,"multithread")==0 ){ |
| 1238 sqlite3_config(SQLITE_CONFIG_MULTITHREAD); |
| 1239 }else if( strcmp(z,"nomemstat")==0 ){ |
| 1240 sqlite3_config(SQLITE_CONFIG_MEMSTATUS, 0); |
1203 }else if( strcmp(z,"nosync")==0 ){ | 1241 }else if( strcmp(z,"nosync")==0 ){ |
1204 noSync = 1; | 1242 noSync = 1; |
1205 }else if( strcmp(z,"notnull")==0 ){ | 1243 }else if( strcmp(z,"notnull")==0 ){ |
1206 g.zNN = "NOT NULL"; | 1244 g.zNN = "NOT NULL"; |
| 1245 #ifdef SQLITE_ENABLE_RBU |
| 1246 }else if( strcmp(z,"rbu")==0 ){ |
| 1247 sqlite3ota_create_vfs("rbu", 0); |
| 1248 sqlite3_vfs_register(sqlite3_vfs_find("rbu"), 1); |
| 1249 #endif |
1207 }else if( strcmp(z,"pagesize")==0 ){ | 1250 }else if( strcmp(z,"pagesize")==0 ){ |
1208 if( i>=argc-1 ) fatal_error("missing argument on %s\n", argv[i]); | 1251 if( i>=argc-1 ) fatal_error("missing argument on %s\n", argv[i]); |
1209 pageSize = integerValue(argv[++i]); | 1252 pageSize = integerValue(argv[++i]); |
1210 }else if( strcmp(z,"pcache")==0 ){ | 1253 }else if( strcmp(z,"pcache")==0 ){ |
1211 if( i>=argc-2 ) fatal_error("missing arguments on %s\n", argv[i]); | 1254 if( i>=argc-2 ) fatal_error("missing arguments on %s\n", argv[i]); |
1212 nPCache = integerValue(argv[i+1]); | 1255 nPCache = integerValue(argv[i+1]); |
1213 szPCache = integerValue(argv[i+2]); | 1256 szPCache = integerValue(argv[i+2]); |
| 1257 doPCache = 1; |
1214 i += 2; | 1258 i += 2; |
1215 }else if( strcmp(z,"primarykey")==0 ){ | 1259 }else if( strcmp(z,"primarykey")==0 ){ |
1216 g.zPK = "PRIMARY KEY"; | 1260 g.zPK = "PRIMARY KEY"; |
1217 }else if( strcmp(z,"reprepare")==0 ){ | 1261 }else if( strcmp(z,"reprepare")==0 ){ |
1218 g.bReprepare = 1; | 1262 g.bReprepare = 1; |
1219 }else if( strcmp(z,"scratch")==0 ){ | 1263 }else if( strcmp(z,"scratch")==0 ){ |
1220 if( i>=argc-2 ) fatal_error("missing arguments on %s\n", argv[i]); | 1264 if( i>=argc-2 ) fatal_error("missing arguments on %s\n", argv[i]); |
1221 nScratch = integerValue(argv[i+1]); | 1265 nScratch = integerValue(argv[i+1]); |
1222 szScratch = integerValue(argv[i+2]); | 1266 szScratch = integerValue(argv[i+2]); |
1223 i += 2; | 1267 i += 2; |
| 1268 }else if( strcmp(z,"serialized")==0 ){ |
| 1269 sqlite3_config(SQLITE_CONFIG_SERIALIZED); |
| 1270 }else if( strcmp(z,"singlethread")==0 ){ |
| 1271 sqlite3_config(SQLITE_CONFIG_SINGLETHREAD); |
1224 }else if( strcmp(z,"sqlonly")==0 ){ | 1272 }else if( strcmp(z,"sqlonly")==0 ){ |
1225 g.bSqlOnly = 1; | 1273 g.bSqlOnly = 1; |
| 1274 }else if( strcmp(z,"shrink-memory")==0 ){ |
| 1275 g.bMemShrink = 1; |
1226 }else if( strcmp(z,"size")==0 ){ | 1276 }else if( strcmp(z,"size")==0 ){ |
1227 if( i>=argc-1 ) fatal_error("missing argument on %s\n", argv[i]); | 1277 if( i>=argc-1 ) fatal_error("missing argument on %s\n", argv[i]); |
1228 g.szTest = integerValue(argv[++i]); | 1278 g.szTest = integerValue(argv[++i]); |
1229 }else if( strcmp(z,"stats")==0 ){ | 1279 }else if( strcmp(z,"stats")==0 ){ |
1230 showStats = 1; | 1280 showStats = 1; |
1231 }else if( strcmp(z,"testset")==0 ){ | 1281 }else if( strcmp(z,"testset")==0 ){ |
1232 if( i>=argc-1 ) fatal_error("missing argument on %s\n", argv[i]); | 1282 if( i>=argc-1 ) fatal_error("missing argument on %s\n", argv[i]); |
1233 zTSet = argv[++i]; | 1283 zTSet = argv[++i]; |
1234 }else if( strcmp(z,"trace")==0 ){ | 1284 }else if( strcmp(z,"trace")==0 ){ |
1235 doTrace = 1; | 1285 doTrace = 1; |
(...skipping 21 matching lines...) Expand all Loading... |
1257 }else{ | 1307 }else{ |
1258 fatal_error("surplus argument: %s\nUse \"%s -?\" for help\n", | 1308 fatal_error("surplus argument: %s\nUse \"%s -?\" for help\n", |
1259 argv[i], argv[0]); | 1309 argv[i], argv[0]); |
1260 } | 1310 } |
1261 } | 1311 } |
1262 #if 0 | 1312 #if 0 |
1263 if( zDbName==0 ){ | 1313 if( zDbName==0 ){ |
1264 fatal_error(zHelp, argv[0]); | 1314 fatal_error(zHelp, argv[0]); |
1265 } | 1315 } |
1266 #endif | 1316 #endif |
| 1317 #if SQLITE_VERSION_NUMBER>=3006001 |
1267 if( nHeap>0 ){ | 1318 if( nHeap>0 ){ |
1268 pHeap = malloc( nHeap ); | 1319 pHeap = malloc( nHeap ); |
1269 if( pHeap==0 ) fatal_error("cannot allocate %d-byte heap\n", nHeap); | 1320 if( pHeap==0 ) fatal_error("cannot allocate %d-byte heap\n", nHeap); |
1270 rc = sqlite3_config(SQLITE_CONFIG_HEAP, pHeap, nHeap, mnHeap); | 1321 rc = sqlite3_config(SQLITE_CONFIG_HEAP, pHeap, nHeap, mnHeap); |
1271 if( rc ) fatal_error("heap configuration failed: %d\n", rc); | 1322 if( rc ) fatal_error("heap configuration failed: %d\n", rc); |
1272 } | 1323 } |
1273 if( nPCache>0 && szPCache>0 ){ | 1324 if( doPCache ){ |
1274 pPCache = malloc( nPCache*(sqlite3_int64)szPCache ); | 1325 if( nPCache>0 && szPCache>0 ){ |
1275 if( pPCache==0 ) fatal_error("cannot allocate %lld-byte pcache\n", | 1326 pPCache = malloc( nPCache*(sqlite3_int64)szPCache ); |
1276 nPCache*(sqlite3_int64)szPCache); | 1327 if( pPCache==0 ) fatal_error("cannot allocate %lld-byte pcache\n", |
| 1328 nPCache*(sqlite3_int64)szPCache); |
| 1329 } |
1277 rc = sqlite3_config(SQLITE_CONFIG_PAGECACHE, pPCache, szPCache, nPCache); | 1330 rc = sqlite3_config(SQLITE_CONFIG_PAGECACHE, pPCache, szPCache, nPCache); |
1278 if( rc ) fatal_error("pcache configuration failed: %d\n", rc); | 1331 if( rc ) fatal_error("pcache configuration failed: %d\n", rc); |
1279 } | 1332 } |
1280 if( nScratch>0 && szScratch>0 ){ | 1333 if( nScratch>0 && szScratch>0 ){ |
1281 pScratch = malloc( nScratch*(sqlite3_int64)szScratch ); | 1334 pScratch = malloc( nScratch*(sqlite3_int64)szScratch ); |
1282 if( pScratch==0 ) fatal_error("cannot allocate %lld-byte scratch\n", | 1335 if( pScratch==0 ) fatal_error("cannot allocate %lld-byte scratch\n", |
1283 nScratch*(sqlite3_int64)szScratch); | 1336 nScratch*(sqlite3_int64)szScratch); |
1284 rc = sqlite3_config(SQLITE_CONFIG_SCRATCH, pScratch, szScratch, nScratch); | 1337 rc = sqlite3_config(SQLITE_CONFIG_SCRATCH, pScratch, szScratch, nScratch); |
1285 if( rc ) fatal_error("scratch configuration failed: %d\n", rc); | 1338 if( rc ) fatal_error("scratch configuration failed: %d\n", rc); |
1286 } | 1339 } |
1287 if( nLook>0 ){ | 1340 if( nLook>0 ){ |
1288 sqlite3_config(SQLITE_CONFIG_LOOKASIDE, 0, 0); | 1341 sqlite3_config(SQLITE_CONFIG_LOOKASIDE, 0, 0); |
1289 } | 1342 } |
| 1343 #endif |
1290 | 1344 |
1291 /* Open the database and the input file */ | 1345 /* Open the database and the input file */ |
1292 if( sqlite3_open(zDbName, &g.db) ){ | 1346 if( sqlite3_open(zDbName, &g.db) ){ |
1293 fatal_error("Cannot open database file: %s\n", zDbName); | 1347 fatal_error("Cannot open database file: %s\n", zDbName); |
1294 } | 1348 } |
| 1349 #if SQLITE_VERSION_NUMBER>=3006001 |
1295 if( nLook>0 && szLook>0 ){ | 1350 if( nLook>0 && szLook>0 ){ |
1296 pLook = malloc( nLook*szLook ); | 1351 pLook = malloc( nLook*szLook ); |
1297 rc = sqlite3_db_config(g.db, SQLITE_DBCONFIG_LOOKASIDE, pLook, szLook,nLook)
; | 1352 rc = sqlite3_db_config(g.db, SQLITE_DBCONFIG_LOOKASIDE, pLook, szLook,nLook)
; |
1298 if( rc ) fatal_error("lookaside configuration failed: %d\n", rc); | 1353 if( rc ) fatal_error("lookaside configuration failed: %d\n", rc); |
1299 } | 1354 } |
| 1355 #endif |
1300 | 1356 |
1301 /* Set database connection options */ | 1357 /* Set database connection options */ |
1302 sqlite3_create_function(g.db, "random", 0, SQLITE_UTF8, 0, randomFunc, 0, 0); | 1358 sqlite3_create_function(g.db, "random", 0, SQLITE_UTF8, 0, randomFunc, 0, 0); |
1303 if( doTrace ) sqlite3_trace(g.db, traceCallback, 0); | 1359 if( doTrace ) sqlite3_trace(g.db, traceCallback, 0); |
1304 speedtest1_exec("PRAGMA threads=%d", nThread); | 1360 speedtest1_exec("PRAGMA threads=%d", nThread); |
1305 if( zKey ){ | 1361 if( zKey ){ |
1306 speedtest1_exec("PRAGMA key('%s')", zKey); | 1362 speedtest1_exec("PRAGMA key('%s')", zKey); |
1307 } | 1363 } |
1308 if( zEncoding ){ | 1364 if( zEncoding ){ |
1309 speedtest1_exec("PRAGMA encoding=%s", zEncoding); | 1365 speedtest1_exec("PRAGMA encoding=%s", zEncoding); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1371 #endif | 1427 #endif |
1372 sqlite3_db_status(g.db, SQLITE_DBSTATUS_SCHEMA_USED, &iCur, &iHi, 0); | 1428 sqlite3_db_status(g.db, SQLITE_DBSTATUS_SCHEMA_USED, &iCur, &iHi, 0); |
1373 printf("-- Schema Heap Usage: %d bytes\n", iCur); | 1429 printf("-- Schema Heap Usage: %d bytes\n", iCur); |
1374 sqlite3_db_status(g.db, SQLITE_DBSTATUS_STMT_USED, &iCur, &iHi, 0); | 1430 sqlite3_db_status(g.db, SQLITE_DBSTATUS_STMT_USED, &iCur, &iHi, 0); |
1375 printf("-- Statement Heap Usage: %d bytes\n", iCur); | 1431 printf("-- Statement Heap Usage: %d bytes\n", iCur); |
1376 } | 1432 } |
1377 #endif | 1433 #endif |
1378 | 1434 |
1379 sqlite3_close(g.db); | 1435 sqlite3_close(g.db); |
1380 | 1436 |
| 1437 #if SQLITE_VERSION_NUMBER>=3006001 |
1381 /* Global memory usage statistics printed after the database connection | 1438 /* Global memory usage statistics printed after the database connection |
1382 ** has closed. Memory usage should be zero at this point. */ | 1439 ** has closed. Memory usage should be zero at this point. */ |
1383 if( showStats ){ | 1440 if( showStats ){ |
1384 sqlite3_status(SQLITE_STATUS_MEMORY_USED, &iCur, &iHi, 0); | 1441 sqlite3_status(SQLITE_STATUS_MEMORY_USED, &iCur, &iHi, 0); |
1385 printf("-- Memory Used (bytes): %d (max %d)\n", iCur,iHi); | 1442 printf("-- Memory Used (bytes): %d (max %d)\n", iCur,iHi); |
1386 #if SQLITE_VERSION_NUMBER>=3007000 | 1443 #if SQLITE_VERSION_NUMBER>=3007000 |
1387 sqlite3_status(SQLITE_STATUS_MALLOC_COUNT, &iCur, &iHi, 0); | 1444 sqlite3_status(SQLITE_STATUS_MALLOC_COUNT, &iCur, &iHi, 0); |
1388 printf("-- Outstanding Allocations: %d (max %d)\n", iCur,iHi); | 1445 printf("-- Outstanding Allocations: %d (max %d)\n", iCur,iHi); |
1389 #endif | 1446 #endif |
1390 sqlite3_status(SQLITE_STATUS_PAGECACHE_OVERFLOW, &iCur, &iHi, 0); | 1447 sqlite3_status(SQLITE_STATUS_PAGECACHE_OVERFLOW, &iCur, &iHi, 0); |
1391 printf("-- Pcache Overflow Bytes: %d (max %d)\n", iCur,iHi); | 1448 printf("-- Pcache Overflow Bytes: %d (max %d)\n", iCur,iHi); |
1392 sqlite3_status(SQLITE_STATUS_SCRATCH_OVERFLOW, &iCur, &iHi, 0); | 1449 sqlite3_status(SQLITE_STATUS_SCRATCH_OVERFLOW, &iCur, &iHi, 0); |
1393 printf("-- Scratch Overflow Bytes: %d (max %d)\n", iCur,iHi); | 1450 printf("-- Scratch Overflow Bytes: %d (max %d)\n", iCur,iHi); |
1394 sqlite3_status(SQLITE_STATUS_MALLOC_SIZE, &iCur, &iHi, 0); | 1451 sqlite3_status(SQLITE_STATUS_MALLOC_SIZE, &iCur, &iHi, 0); |
1395 printf("-- Largest Allocation: %d bytes\n",iHi); | 1452 printf("-- Largest Allocation: %d bytes\n",iHi); |
1396 sqlite3_status(SQLITE_STATUS_PAGECACHE_SIZE, &iCur, &iHi, 0); | 1453 sqlite3_status(SQLITE_STATUS_PAGECACHE_SIZE, &iCur, &iHi, 0); |
1397 printf("-- Largest Pcache Allocation: %d bytes\n",iHi); | 1454 printf("-- Largest Pcache Allocation: %d bytes\n",iHi); |
1398 sqlite3_status(SQLITE_STATUS_SCRATCH_SIZE, &iCur, &iHi, 0); | 1455 sqlite3_status(SQLITE_STATUS_SCRATCH_SIZE, &iCur, &iHi, 0); |
1399 printf("-- Largest Scratch Allocation: %d bytes\n", iHi); | 1456 printf("-- Largest Scratch Allocation: %d bytes\n", iHi); |
1400 } | 1457 } |
| 1458 #endif |
1401 | 1459 |
1402 /* Release memory */ | 1460 /* Release memory */ |
1403 free( pLook ); | 1461 free( pLook ); |
1404 free( pPCache ); | 1462 free( pPCache ); |
1405 free( pScratch ); | 1463 free( pScratch ); |
1406 free( pHeap ); | 1464 free( pHeap ); |
1407 return 0; | 1465 return 0; |
1408 } | 1466 } |
OLD | NEW |