/ Check-in [62a4851c]
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:Enhancements to the kvtest utility program. Add the --jmode option. Improved output formatting.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 62a4851ccf88837d1c16dae8204f7f264e80e3c9
User & Date: drh 2017-01-26 01:54:39
Context
2017-01-26
02:26
Make SQLITE_DIRECT_OVERFLOW_READ work for in WAL mode as long as the page being read is not in the the -wal file. check-in: 9879be18 user: drh tags: trunk
01:54
Enhancements to the kvtest utility program. Add the --jmode option. Improved output formatting. check-in: 62a4851c user: drh tags: trunk
00:58
Modify the ICU extension to use a static initializer, as VC++ complains about a dynamic initialization. Maybe the dynamic structure initialization is a GCC extension. This fixes a problem identified on the SQLite mailing list by Ziemowit Laski. check-in: 50e60cb4 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to test/kvtest.c.

    75     75   "        files in DIRECTORY.\n"
    76     76   "\n"
    77     77   "   kvtest run DBFILE [options]\n"
    78     78   "\n"
    79     79   "        Run a performance test.  DBFILE can be either the name of a\n"
    80     80   "        database or a directory containing sample files.  Options:\n"
    81     81   "\n"
    82         -"             --asc                Read blobs in ascending order\n"
    83         -"             --blob-api           Use the BLOB API\n"
    84         -"             --cache-size N       Database cache size\n"
    85         -"             --count N            Read N blobs\n"
    86         -"             --desc               Read blobs in descending order\n"
    87         -"             --max-id N           Maximum blob key to use\n"
    88         -"             --mmap N             Mmap as much as N bytes of DBFILE\n"
    89         -"             --random             Read blobs in a random order\n"
    90         -"             --start N            Start reading with this blob key\n"
    91         -"             --stats              Output operating stats before exiting\n"
           82  +"           --asc                  Read blobs in ascending order\n"
           83  +"           --blob-api             Use the BLOB API\n"
           84  +"           --cache-size N         Database cache size\n"
           85  +"           --count N              Read N blobs\n"
           86  +"           --desc                 Read blobs in descending order\n"
           87  +"           --max-id N             Maximum blob key to use\n"
           88  +"           --mmap N               Mmap as much as N bytes of DBFILE\n"
           89  +"           --jmode MODE           Set MODE journal mode prior to starting\n"
           90  +"           --random               Read blobs in a random order\n"
           91  +"           --start N              Start reading with this blob key\n"
           92  +"           --stats                Output operating stats before exiting\n"
    92     93   ;
    93     94   
    94     95   /* Reference resources used */
    95     96   #include <stdio.h>
    96     97   #include <stdlib.h>
    97     98   #include <sys/types.h>
    98     99   #include <sys/stat.h>
................................................................................
   535    536     fprintf(out, "Page cache writes:                   %d\n", iCur);
   536    537     iHiwtr = iCur = -1;
   537    538   
   538    539   #ifdef __linux__
   539    540     displayLinuxIoStats(out);
   540    541   #endif
   541    542   
   542         -  /* Do not remove this machine readable comment: extra-stats-output-here */
   543         -
   544         -  fprintf(out, "\n");
   545    543     return 0;
   546    544   }
   547    545   
   548    546   /* Blob access order */
   549    547   #define ORDER_ASC     1
   550    548   #define ORDER_DESC    2
   551    549   #define ORDER_RANDOM  3
................................................................................
   558    556     int eType;                  /* Is zDb a database or a directory? */
   559    557     char *zDb;                  /* Database or directory name */
   560    558     int i;                      /* Loop counter */
   561    559     int rc;                     /* Return code from SQLite calls */
   562    560     int nCount = 1000;          /* Number of blob fetch operations */
   563    561     int nExtra = 0;             /* Extra cycles */
   564    562     int iKey = 1;               /* Next blob key */
   565         -  int iMax = 1000;            /* Largest allowed key */
          563  +  int iMax = 0;               /* Largest allowed key */
   566    564     int iPagesize = 0;          /* Database page size */
   567    565     int iCache = 1000;          /* Database cache size in kibibytes */
   568    566     int bBlobApi = 0;           /* Use the incremental blob I/O API */
   569    567     int bStats = 0;             /* Print stats before exiting */
   570    568     int eOrder = ORDER_ASC;     /* Access order */
   571    569     sqlite3 *db = 0;            /* Database connection */
   572    570     sqlite3_stmt *pStmt = 0;    /* Prepared statement for SQL access */
................................................................................
   574    572     sqlite3_int64 tmStart;      /* Start time */
   575    573     sqlite3_int64 tmElapsed;    /* Elapsed time */
   576    574     int mmapSize = 0;           /* --mmap N argument */
   577    575     int nData = 0;              /* Bytes of data */
   578    576     sqlite3_int64 nTotal = 0;   /* Total data read */
   579    577     unsigned char *pData = 0;   /* Content of the blob */
   580    578     int nAlloc = 0;             /* Space allocated for pData[] */
          579  +  const char *zJMode = 0;     /* Journal mode */
   581    580     
   582    581   
   583    582     assert( strcmp(argv[1],"run")==0 );
   584    583     assert( argc>=3 );
   585    584     zDb = argv[2];
   586    585     eType = pathType(zDb);
   587    586     if( eType==PATH_OTHER ) fatalError("unknown object type: \"%s\"", zDb);
................................................................................
   601    600         mmapSize = integerValue(argv[++i]);
   602    601         if( nCount<0 ) fatalError("the --mmap must be non-negative");
   603    602         continue;
   604    603       }
   605    604       if( strcmp(z, "-max-id")==0 ){
   606    605         if( i==argc-1 ) fatalError("missing argument on \"%s\"", argv[i]);
   607    606         iMax = integerValue(argv[++i]);
   608         -      if( iMax<1 ) fatalError("the --max-id must be positive");
   609    607         continue;
   610    608       }
   611    609       if( strcmp(z, "-start")==0 ){
   612    610         if( i==argc-1 ) fatalError("missing argument on \"%s\"", argv[i]);
   613    611         iKey = integerValue(argv[++i]);
   614    612         if( iKey<1 ) fatalError("the --start must be positive");
   615    613         continue;
   616    614       }
   617    615       if( strcmp(z, "-cache-size")==0 ){
   618    616         if( i==argc-1 ) fatalError("missing argument on \"%s\"", argv[i]);
   619    617         iCache = integerValue(argv[++i]);
   620    618         continue;
          619  +    }
          620  +    if( strcmp(z, "-jmode")==0 ){
          621  +      if( i==argc-1 ) fatalError("missing argument on \"%s\"", argv[i]);
          622  +      zJMode = argv[++i];
          623  +      continue;
   621    624       }
   622    625       if( strcmp(z, "-random")==0 ){
   623    626         eOrder = ORDER_RANDOM;
   624    627         continue;
   625    628       }
   626    629       if( strcmp(z, "-asc")==0 ){
   627    630         eOrder = ORDER_ASC;
................................................................................
   662    665       sqlite3_prepare_v2(db, "PRAGMA cache_size", -1, &pStmt, 0);
   663    666       if( sqlite3_step(pStmt)==SQLITE_ROW ){
   664    667         iCache = sqlite3_column_int(pStmt, 0);
   665    668       }else{
   666    669         iCache = 0;
   667    670       }
   668    671       sqlite3_finalize(pStmt);
          672  +    pStmt = 0;
          673  +    if( zJMode ){
          674  +      zSql = sqlite3_mprintf("PRAGMA journal_mode=%Q", zJMode);
          675  +      sqlite3_exec(db, zSql, 0, 0, 0);
          676  +      sqlite3_free(zSql);
          677  +    }
          678  +    sqlite3_prepare_v2(db, "PRAGMA journal_mode", -1, &pStmt, 0);
          679  +    if( sqlite3_step(pStmt)==SQLITE_ROW ){
          680  +      zJMode = sqlite3_mprintf("%s", sqlite3_column_text(pStmt, 0));
          681  +    }else{
          682  +      zJMode = "???";
          683  +    }
          684  +    sqlite3_finalize(pStmt);
          685  +    if( iMax<=0 ){
          686  +      sqlite3_prepare_v2(db, "SELECT max(k) FROM kv", -1, &pStmt, 0);
          687  +      if( sqlite3_step(pStmt)==SQLITE_ROW ){
          688  +        iMax = sqlite3_column_int(pStmt, 0);
          689  +      }
          690  +      sqlite3_finalize(pStmt);
          691  +    }
   669    692       pStmt = 0;
   670    693       sqlite3_exec(db, "BEGIN", 0, 0, 0);
   671    694     }
          695  +  if( iMax<=0 ) iMax = 1000;
   672    696     for(i=0; i<nCount; i++){
   673    697       if( eType==PATH_DIR ){
   674    698         /* CASE 1: Reading blobs out of separate files */
   675    699         char *zKey;
   676    700         zKey = sqlite3_mprintf("%s/%06d", zDb, iKey);
   677    701         nData = 0;
   678    702         pData = readFile(zKey, &nData);
................................................................................
   745    769     if( nExtra ){
   746    770       printf("%d cycles due to %d misses\n", nCount, nExtra);
   747    771     }
   748    772     if( eType==PATH_DB ){
   749    773       printf("SQLite version: %s\n", sqlite3_libversion());
   750    774     }
   751    775     printf("--count %d --max-id %d", nCount-nExtra, iMax);
   752         -  if( eType==PATH_DB ){
   753         -    printf(" --cache-size %d", iCache);
   754         -  }
   755    776     switch( eOrder ){
   756    777       case ORDER_RANDOM:  printf(" --random\n");  break;
   757    778       case ORDER_DESC:    printf(" --desc\n");    break;
   758    779       default:            printf(" --asc\n");     break;
   759    780     }
          781  +  if( eType==PATH_DB ){
          782  +    printf("--cache-size %d --jmode %s\n", iCache, zJMode);
          783  +    printf("--mmap %d%s\n", mmapSize, bBlobApi ? " --blob-api" : "");
          784  +  }
   760    785     if( iPagesize ) printf("Database page size: %d\n", iPagesize);
   761    786     printf("Total elapsed time: %.3f\n", tmElapsed/1000.0);
   762    787     printf("Microseconds per BLOB read: %.3f\n", tmElapsed*1000.0/nCount);
   763    788     printf("Content read rate: %.1f MB/s\n", nTotal/(1000.0*tmElapsed));
   764    789     return 0;
   765    790   }
   766    791