/ Check-in [118f5c05]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Enhance the ".stats" dot-command in the CLI to use sqlite3_status64() instead of sqlite3_status().
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 118f5c0564fef70cbd06fc0d9dbb2baec162cc39
User & Date: drh 2017-03-10 14:36:10
Context
2017-03-10
16:22
Add the -DSQLITE_MAX_MEMORY=N compile-time option. The default is no limit. check-in: eabd4ef4 user: drh tags: trunk
15:55
Add the SQLITE_MAX_MEMORY compile-time option that provides a hard upper bound on the amount of memory that SQLite will use, per process. Closed-Leaf check-in: 77dfe2ab user: drh tags: max-memory-option
14:36
Enhance the ".stats" dot-command in the CLI to use sqlite3_status64() instead of sqlite3_status(). check-in: 118f5c05 user: drh tags: trunk
01:05
Improvements to ".selftest --init". Tests are number in increments of 10 starting with 100. The tests are generated inside a SAVEPOINT. Errors are reported during test generation. Tests can be appended to existing tests. Add a test case to verify the schema. check-in: b044b152 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/shell.c.

  2255   2255         }
  2256   2256       }
  2257   2257     }
  2258   2258     fclose(in);
  2259   2259   }
  2260   2260   #endif
  2261   2261   
         2262  +/*
         2263  +** Display a single line of status using 64-bit values.
         2264  +*/
         2265  +static void displayStatLine(
         2266  +  ShellState *p,            /* The shell context */
         2267  +  char *zLabel,             /* Label for this one line */
         2268  +  char *zFormat,            /* Format for the result */
         2269  +  int iStatusCtrl,          /* Which status to display */
         2270  +  int bReset                /* True to reset the stats */
         2271  +){
         2272  +  sqlite3_int64 iCur = -1;
         2273  +  sqlite3_int64 iHiwtr = -1;
         2274  +  int i, nPercent;
         2275  +  char zLine[200];
         2276  +  sqlite3_status64(iStatusCtrl, &iCur, &iHiwtr, bReset);
         2277  +  for(i=0, nPercent=0; zFormat[i]; i++){
         2278  +    if( zFormat[i]=='%' ) nPercent++;
         2279  +  }
         2280  +  if( nPercent>1 ){
         2281  +    sqlite3_snprintf(sizeof(zLine), zLine, zFormat, iCur, iHiwtr);
         2282  +  }else{
         2283  +    sqlite3_snprintf(sizeof(zLine), zLine, zFormat, iHiwtr);
         2284  +  }
         2285  +  raw_printf(p->out, "%-36s %s\n", zLabel, zLine);
         2286  +}
  2262   2287   
  2263   2288   /*
  2264   2289   ** Display memory stats.
  2265   2290   */
  2266   2291   static int display_stats(
  2267   2292     sqlite3 *db,                /* Database to query */
  2268   2293     ShellState *pArg,           /* Pointer to ShellState */
  2269   2294     int bReset                  /* True to reset the stats */
  2270   2295   ){
  2271   2296     int iCur;
  2272   2297     int iHiwtr;
  2273   2298   
  2274   2299     if( pArg && pArg->out ){
  2275         -
  2276         -    iHiwtr = iCur = -1;
  2277         -    sqlite3_status(SQLITE_STATUS_MEMORY_USED, &iCur, &iHiwtr, bReset);
  2278         -    raw_printf(pArg->out,
  2279         -            "Memory Used:                         %d (max %d) bytes\n",
  2280         -            iCur, iHiwtr);
  2281         -    iHiwtr = iCur = -1;
  2282         -    sqlite3_status(SQLITE_STATUS_MALLOC_COUNT, &iCur, &iHiwtr, bReset);
  2283         -    raw_printf(pArg->out, "Number of Outstanding Allocations:   %d (max %d)\n",
  2284         -            iCur, iHiwtr);
         2300  +    displayStatLine(pArg, "Memory Used:",
         2301  +       "%lld (max %lld) bytes", SQLITE_STATUS_MEMORY_USED, bReset);
         2302  +    displayStatLine(pArg, "Number of Outstanding Allocations:",
         2303  +       "%lld (max %lld)", SQLITE_STATUS_MALLOC_COUNT, bReset);
  2285   2304       if( pArg->shellFlgs & SHFLG_Pagecache ){
  2286         -      iHiwtr = iCur = -1;
  2287         -      sqlite3_status(SQLITE_STATUS_PAGECACHE_USED, &iCur, &iHiwtr, bReset);
  2288         -      raw_printf(pArg->out,
  2289         -              "Number of Pcache Pages Used:         %d (max %d) pages\n",
  2290         -              iCur, iHiwtr);
         2305  +      displayStatLine(pArg, "Number of Pcache Pages Used:",
         2306  +         "%lld (max %lld) pages", SQLITE_STATUS_PAGECACHE_USED, bReset);
  2291   2307       }
  2292         -    iHiwtr = iCur = -1;
  2293         -    sqlite3_status(SQLITE_STATUS_PAGECACHE_OVERFLOW, &iCur, &iHiwtr, bReset);
  2294         -    raw_printf(pArg->out,
  2295         -            "Number of Pcache Overflow Bytes:     %d (max %d) bytes\n",
  2296         -            iCur, iHiwtr);
         2308  +    displayStatLine(pArg, "Number of Pcache Overflow Bytes:",
         2309  +       "%lld (max %lld) bytes", SQLITE_STATUS_PAGECACHE_OVERFLOW, bReset);
  2297   2310       if( pArg->shellFlgs & SHFLG_Scratch ){
  2298         -      iHiwtr = iCur = -1;
  2299         -      sqlite3_status(SQLITE_STATUS_SCRATCH_USED, &iCur, &iHiwtr, bReset);
  2300         -      raw_printf(pArg->out,
  2301         -              "Number of Scratch Allocations Used:  %d (max %d)\n",
  2302         -              iCur, iHiwtr);
         2311  +      displayStatLine(pArg, "Number of Scratch Allocations Used:",
         2312  +         "%lld (max %lld)", SQLITE_STATUS_SCRATCH_USED, bReset);
  2303   2313       }
  2304         -    iHiwtr = iCur = -1;
  2305         -    sqlite3_status(SQLITE_STATUS_SCRATCH_OVERFLOW, &iCur, &iHiwtr, bReset);
  2306         -    raw_printf(pArg->out,
  2307         -            "Number of Scratch Overflow Bytes:    %d (max %d) bytes\n",
  2308         -            iCur, iHiwtr);
  2309         -    iHiwtr = iCur = -1;
  2310         -    sqlite3_status(SQLITE_STATUS_MALLOC_SIZE, &iCur, &iHiwtr, bReset);
  2311         -    raw_printf(pArg->out, "Largest Allocation:                  %d bytes\n",
  2312         -            iHiwtr);
  2313         -    iHiwtr = iCur = -1;
  2314         -    sqlite3_status(SQLITE_STATUS_PAGECACHE_SIZE, &iCur, &iHiwtr, bReset);
  2315         -    raw_printf(pArg->out, "Largest Pcache Allocation:           %d bytes\n",
  2316         -            iHiwtr);
  2317         -    iHiwtr = iCur = -1;
  2318         -    sqlite3_status(SQLITE_STATUS_SCRATCH_SIZE, &iCur, &iHiwtr, bReset);
  2319         -    raw_printf(pArg->out, "Largest Scratch Allocation:          %d bytes\n",
  2320         -            iHiwtr);
         2314  +    displayStatLine(pArg, "Number of Scratch Overflow Bytes:",
         2315  +       "%lld (max %lld) bytes", SQLITE_STATUS_SCRATCH_OVERFLOW, bReset);
         2316  +    displayStatLine(pArg, "Largest Allocation:",
         2317  +       "%lld bytes", SQLITE_STATUS_MALLOC_SIZE, bReset);
         2318  +    displayStatLine(pArg, "Largest Pcache Allocation:",
         2319  +       "%lld bytes", SQLITE_STATUS_PAGECACHE_SIZE, bReset);
         2320  +    displayStatLine(pArg, "Largest Scratch Allocation:",
         2321  +       "%lld bytes", SQLITE_STATUS_SCRATCH_SIZE, bReset);
  2321   2322   #ifdef YYTRACKMAXSTACKDEPTH
  2322         -    iHiwtr = iCur = -1;
  2323         -    sqlite3_status(SQLITE_STATUS_PARSER_STACK, &iCur, &iHiwtr, bReset);
  2324         -    raw_printf(pArg->out, "Deepest Parser Stack:                %d (max %d)\n",
  2325         -            iCur, iHiwtr);
         2323  +    displayStatLine(pArg, "Deepest Parser Stack:",
         2324  +       "%lld (max %lld)", SQLITE_STATUS_PARSER_STACK, bReset);
  2326   2325   #endif
  2327   2326     }
  2328   2327   
  2329   2328     if( pArg && pArg->out && db ){
  2330   2329       if( pArg->shellFlgs & SHFLG_Lookaside ){
  2331   2330         iHiwtr = iCur = -1;
  2332   2331         sqlite3_db_status(db, SQLITE_DBSTATUS_LOOKASIDE_USED,