]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Add option "--stats" to test program kvtest. Specifying --stats causes kvtest
authordan <dan@noemail.net>
Fri, 20 Jan 2017 16:46:20 +0000 (16:46 +0000)
committerdan <dan@noemail.net>
Fri, 20 Jan 2017 16:46:20 +0000 (16:46 +0000)
to output information similar to the shell tool option of the same name.

FossilOrigin-Name: 90291327fc127671d9847a4a2ce1ed47a408cfc6

manifest
manifest.uuid
test/kvtest.c

index b018d640fc82e0838f03f8fe12dd638a54e6aa83..882b5a775a3d5a218d7a3691eccd23238f251fcc 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Get\sthe\s"--testset\srtree"\soption\sworking\son\sspeedtest1.\s\sAdd\sthe\s--rtree,\n--lookaside,\sand\s--clang\soptions\sto\sthe\sspeed-check.sh\sscript.
-D 2017-01-20T16:09:12.221
+C Add\soption\s"--stats"\sto\stest\sprogram\skvtest.\sSpecifying\s--stats\scauses\skvtest\nto\soutput\sinformation\ssimilar\sto\sthe\sshell\stool\soption\sof\sthe\ssame\sname.
+D 2017-01-20T16:46:20.421
 F Makefile.in 41bd4cad981487345c4a84081074bcdb876e4b2e
 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
 F Makefile.msc b8ca53350ae545e3562403d5da2a69cec79308da
@@ -898,7 +898,7 @@ F test/json101.test c0897616f32d95431f37fd291cb78742181980ac
 F test/json102.test bf3fe7a706d30936a76a0f7a0375e1e8e73aff5a
 F test/json103.test c5f6b85e69de05f6b3195f9f9d5ce9cd179099a0
 F test/keyword1.test 37ef6bba5d2ed5b07ecdd6810571de2956599dff
-F test/kvtest.c 2c66ddefcd03c2caa337f6dd79e6c82368af83df
+F test/kvtest.c da3fddb003221d3d9726afd959d9c6017516fd02
 F test/lastinsert.test 42e948fd6442f07d60acbd15d33fb86473e0ef63
 F test/laststmtchanges.test ae613f53819206b3222771828d024154d51db200
 F test/like.test 0603f4fa0dad50987f70032c05800cbfa8985302
@@ -1547,7 +1547,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P 52a61967d920047ea0b4409b79793e05c0128964
-R 4e64e669335e5bcf79eed63ea8c1840b
-U drh
-Z 6f7214599f293ddc9e6d41b975d33fdf
+P 87b640c8d07a76b2bc7e896e01965cc09e06f77b
+R b9affb78955ec88bf34da37dcc1dd9ef
+U dan
+Z 3096b993434f8157eb2ffff3d1e5a264
index 55a46f08851e17f9dd9a113d36514fdf85fdf95b..f7dbcbe1e3087e30cf675689fb1bd1c8cce99a78 100644 (file)
@@ -1 +1 @@
-87b640c8d07a76b2bc7e896e01965cc09e06f77b
\ No newline at end of file
+90291327fc127671d9847a4a2ce1ed47a408cfc6
\ No newline at end of file
index 877605aced4430b66a368efef550a54550fffe42..8458ef919c0f68ffb88703c343647dac7428a74f 100644 (file)
@@ -87,6 +87,7 @@ static const char zHelp[] =
 "             --max-id N           Maximum blob key to use\n"
 "             --random             Read blobs in a random order\n"
 "             --start N            Start reading with this blob key\n"
+"             --stats              Output operating stats before exiting\n"
 ;
 
 /* Reference resources used */
@@ -369,6 +370,122 @@ static sqlite3_int64 timeOfDay(void){
   return t;
 }
 
+#ifdef __linux__
+/*
+** Attempt to display I/O stats on Linux using /proc/PID/io
+*/
+static void displayLinuxIoStats(FILE *out){
+  FILE *in;
+  char z[200];
+  sqlite3_snprintf(sizeof(z), z, "/proc/%d/io", getpid());
+  in = fopen(z, "rb");
+  if( in==0 ) return;
+  while( fgets(z, sizeof(z), in)!=0 ){
+    static const struct {
+      const char *zPattern;
+      const char *zDesc;
+    } aTrans[] = {
+      { "rchar: ",                  "Bytes received by read():" },
+      { "wchar: ",                  "Bytes sent to write():"    },
+      { "syscr: ",                  "Read() system calls:"      },
+      { "syscw: ",                  "Write() system calls:"     },
+      { "read_bytes: ",             "Bytes read from storage:"  },
+      { "write_bytes: ",            "Bytes written to storage:" },
+      { "cancelled_write_bytes: ",  "Cancelled write bytes:"    },
+    };
+    int i;
+    for(i=0; i<sizeof(aTrans)/sizeof(aTrans[0]); i++){
+      int n = (int)strlen(aTrans[i].zPattern);
+      if( strncmp(aTrans[i].zPattern, z, n)==0 ){
+        fprintf(out, "%-36s %s", aTrans[i].zDesc, &z[n]);
+        break;
+      }
+    }
+  }
+  fclose(in);
+}
+#endif
+
+/*
+** Display memory stats.
+*/
+static int display_stats(
+  sqlite3 *db,                    /* Database to query */
+  int bReset                      /* True to reset SQLite stats */
+){
+  int iCur;
+  int iHiwtr;
+  FILE *out = stdout;
+
+  fprintf(out, "\n");
+
+  iHiwtr = iCur = -1;
+  sqlite3_status(SQLITE_STATUS_MEMORY_USED, &iCur, &iHiwtr, bReset);
+  fprintf(out,
+          "Memory Used:                         %d (max %d) bytes\n",
+          iCur, iHiwtr);
+  iHiwtr = iCur = -1;
+  sqlite3_status(SQLITE_STATUS_MALLOC_COUNT, &iCur, &iHiwtr, bReset);
+  fprintf(out, "Number of Outstanding Allocations:   %d (max %d)\n",
+          iCur, iHiwtr);
+  iHiwtr = iCur = -1;
+  sqlite3_status(SQLITE_STATUS_PAGECACHE_USED, &iCur, &iHiwtr, bReset);
+  fprintf(out,
+      "Number of Pcache Pages Used:         %d (max %d) pages\n",
+      iCur, iHiwtr);
+  iHiwtr = iCur = -1;
+  sqlite3_status(SQLITE_STATUS_PAGECACHE_OVERFLOW, &iCur, &iHiwtr, bReset);
+  fprintf(out,
+          "Number of Pcache Overflow Bytes:     %d (max %d) bytes\n",
+          iCur, iHiwtr);
+  iHiwtr = iCur = -1;
+  sqlite3_status(SQLITE_STATUS_SCRATCH_USED, &iCur, &iHiwtr, bReset);
+  fprintf(out,
+      "Number of Scratch Allocations Used:  %d (max %d)\n",
+      iCur, iHiwtr);
+  iHiwtr = iCur = -1;
+  sqlite3_status(SQLITE_STATUS_SCRATCH_OVERFLOW, &iCur, &iHiwtr, bReset);
+  fprintf(out,
+          "Number of Scratch Overflow Bytes:    %d (max %d) bytes\n",
+          iCur, iHiwtr);
+  iHiwtr = iCur = -1;
+  sqlite3_status(SQLITE_STATUS_MALLOC_SIZE, &iCur, &iHiwtr, bReset);
+  fprintf(out, "Largest Allocation:                  %d bytes\n",
+          iHiwtr);
+  iHiwtr = iCur = -1;
+  sqlite3_status(SQLITE_STATUS_PAGECACHE_SIZE, &iCur, &iHiwtr, bReset);
+  fprintf(out, "Largest Pcache Allocation:           %d bytes\n",
+          iHiwtr);
+  iHiwtr = iCur = -1;
+  sqlite3_status(SQLITE_STATUS_SCRATCH_SIZE, &iCur, &iHiwtr, bReset);
+  fprintf(out, "Largest Scratch Allocation:          %d bytes\n",
+          iHiwtr);
+
+  iHiwtr = iCur = -1;
+  sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_USED, &iCur, &iHiwtr, bReset);
+  fprintf(out, "Pager Heap Usage:                    %d bytes\n",
+      iCur);
+  iHiwtr = iCur = -1;
+  sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_HIT, &iCur, &iHiwtr, 1);
+  fprintf(out, "Page cache hits:                     %d\n", iCur);
+  iHiwtr = iCur = -1;
+  sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_MISS, &iCur, &iHiwtr, 1);
+  fprintf(out, "Page cache misses:                   %d\n", iCur);
+  iHiwtr = iCur = -1;
+  sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_WRITE, &iCur, &iHiwtr, 1);
+  fprintf(out, "Page cache writes:                   %d\n", iCur);
+  iHiwtr = iCur = -1;
+
+#ifdef __linux__
+  displayLinuxIoStats(out);
+#endif
+
+  /* Do not remove this machine readable comment: extra-stats-output-here */
+
+  fprintf(out, "\n");
+  return 0;
+}
+
 /* Blob access order */
 #define ORDER_ASC     1
 #define ORDER_DESC    2
@@ -389,6 +506,7 @@ static int runMain(int argc, char **argv){
   int iPagesize = 0;          /* Database page size */
   int iCache = 1000;          /* Database cache size in kibibytes */
   int bBlobApi = 0;           /* Use the incremental blob I/O API */
+  int bStats = 0;             /* Print stats before exiting */
   int eOrder = ORDER_ASC;     /* Access order */
   sqlite3 *db = 0;            /* Database connection */
   sqlite3_stmt *pStmt = 0;    /* Prepared statement for SQL access */
@@ -449,6 +567,10 @@ static int runMain(int argc, char **argv){
       bBlobApi = 1;
       continue;
     }
+    if( strcmp(z, "-stats")==0 ){
+      bStats = 1;
+      continue;
+    }
     fatalError("unknown option: \"%s\"", argv[i]);
   }
   tmStart = timeOfDay();
@@ -542,6 +664,9 @@ static int runMain(int argc, char **argv){
   }
   if( pStmt ) sqlite3_finalize(pStmt);
   if( pBlob ) sqlite3_blob_close(pBlob);
+  if( bStats ){
+    display_stats(db, 0);
+  }
   if( db ) sqlite3_close(db);
   tmElapsed = timeOfDay() - tmStart;
   if( nExtra ){