]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Add the "stat" command to kvtest.c. Also add the --variance option to the
authordrh <drh@noemail.net>
Tue, 31 Jan 2017 15:29:05 +0000 (15:29 +0000)
committerdrh <drh@noemail.net>
Tue, 31 Jan 2017 15:29:05 +0000 (15:29 +0000)
"init" command.  Add the tool/kvtest-speed.sh script used for doing
performance testing on key/value access patterns.

FossilOrigin-Name: b63deed600b1a457a6960ebad5645f4de9c56e5d

manifest
manifest.uuid
test/kvtest.c
tool/kvtest-speed.sh [new file with mode: 0644]

index 8e4b6f544ae3d7df2a0580e65eb5316542cb6217..e0848cf1228438b561031375253c06ff190e550e 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Fix\sa\stypo\sin\sa\scomment.
-D 2017-01-31T15:27:04.928
+C Add\sthe\s"stat"\scommand\sto\skvtest.c.\s\sAlso\sadd\sthe\s--variance\soption\sto\sthe\n"init"\scommand.\s\sAdd\sthe\stool/kvtest-speed.sh\sscript\sused\sfor\sdoing\s\nperformance\stesting\son\skey/value\saccess\spatterns.
+D 2017-01-31T15:29:05.242
 F Makefile.in 5f415e7867296d678fed2e6779aea10c1318b4bc
 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
 F Makefile.msc b8ca53350ae545e3562403d5da2a69cec79308da
@@ -899,7 +899,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 dc6e5e9066fa5e19f7368c7dfbe8c6b9642a706f
+F test/kvtest.c 7a3c38ee56b9cc45dc5a5edc50fd9bc9425659a9
 F test/lastinsert.test 42e948fd6442f07d60acbd15d33fb86473e0ef63
 F test/laststmtchanges.test ae613f53819206b3222771828d024154d51db200
 F test/like.test 0603f4fa0dad50987f70032c05800cbfa8985302
@@ -1475,6 +1475,7 @@ F tool/fuzzershell.c dbf6c26eef936ec78cb0707570de3a4308b2507e
 F tool/genfkey.README cf68fddd4643bbe3ff8e31b8b6d8b0a1b85e20f4
 F tool/genfkey.test 4196a8928b78f51d54ef58e99e99401ab2f0a7e5
 F tool/getlock.c f4c39b651370156cae979501a7b156bdba50e7ce
+F tool/kvtest-speed.sh d6c7c2b5787f44c3be2ed01c8463223032ee598b
 F tool/lemon.c 5ccba178a8e8a4b21e1c9232944d23973da38ad7
 F tool/lempar.c db1bdb4821f2d8fbd76e577cf3ab18642c8d08d1
 F tool/libvers.c caafc3b689638a1d88d44bc5f526c2278760d9b9
@@ -1548,7 +1549,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 eacfdcf25796ea29b5e63499c3d7397498305ad9
-R 08311637f9a8170c29c38d1bfabeb653
+P bd22bf9cbe028e9811ca3afaadafd90312cb0fc9
+R 561f5ef3a58c98c17f69cad51ae91935
 U drh
-Z 855f1082721037fd6fefeb16ca2ac959
+Z 35fd92fc5491c4b603aa832f4a4ebf7a
index 61e2f28112e5ab45ab2c3aa479301696094cde74..69a91341caf48aa16cb7f8294a009659d34c147d 100644 (file)
@@ -1 +1 @@
-bd22bf9cbe028e9811ca3afaadafd90312cb0fc9
\ No newline at end of file
+b63deed600b1a457a6960ebad5645f4de9c56e5d
\ No newline at end of file
index 765a7ee968ac64373d3dc890a47806f3326d3e92..2a108aa4701faa54b0ef63f7cddfccd5fea8eb4d 100644 (file)
@@ -67,13 +67,19 @@ static const char zHelp[] =
 "\n"
 "        Generate a new test database file named DBFILE containing N\n"
 "        BLOBs each of size M bytes.  The page size of the new database\n"
-"        file will be X\n"
+"        file will be X.  Additional options:\n"
+"\n"
+"           --variance V           Randomly vary M by plus or minus V\n"
 "\n"
 "   kvtest export DBFILE DIRECTORY\n"
 "\n"
 "        Export all the blobs in the kv table of DBFILE into separate\n"
 "        files in DIRECTORY.\n"
 "\n"
+"   kvtest stat DBFILE\n"
+"\n"
+"        Display summary information about DBFILE\n"
+"\n"
 "   kvtest run DBFILE [options]\n"
 "\n"
 "        Run a performance test.  DBFILE can be either the name of a\n"
@@ -251,6 +257,7 @@ static int initMain(int argc, char **argv){
   int i, rc;
   int nCount = 1000;
   int sz = 10000;
+  int iVariance = 0;
   int pgsz = 4096;
   sqlite3 *db;
   char *zSql;
@@ -275,6 +282,11 @@ static int initMain(int argc, char **argv){
       if( sz<1 ) fatalError("the --size must be positive");
       continue;
     }
+    if( strcmp(z, "-variance")==0 ){
+      if( i==argc-1 ) fatalError("missing argument on \"%s\"", argv[i]);
+      iVariance = integerValue(argv[++i]);
+      continue;
+    }
     if( strcmp(z, "-pagesize")==0 ){
       if( i==argc-1 ) fatalError("missing argument on \"%s\"", argv[i]);
       pgsz = integerValue(argv[++i]);
@@ -296,9 +308,9 @@ static int initMain(int argc, char **argv){
     "BEGIN;\n"
     "CREATE TABLE kv(k INTEGER PRIMARY KEY, v BLOB);\n"
     "WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<%d)"
-    " INSERT INTO kv(k,v) SELECT x, randomblob(%d) FROM c;\n"
+    " INSERT INTO kv(k,v) SELECT x, randomblob(%d+(random()%%(%d))) FROM c;\n"
     "COMMIT;\n",
-    pgsz, nCount, sz
+    pgsz, nCount, sz, iVariance
   );
   rc = sqlite3_exec(db, zSql, 0, 0, &zErrMsg);
   if( rc ) fatalError("database create failed: %s", zErrMsg);
@@ -307,6 +319,65 @@ static int initMain(int argc, char **argv){
   return 0;
 }
 
+/*
+** Analyze an existing database file.  Report its content.
+*/
+static int statMain(int argc, char **argv){
+  char *zDb;
+  int i, rc;
+  sqlite3 *db;
+  char *zSql;
+  sqlite3_stmt *pStmt;
+
+  assert( strcmp(argv[1],"stat")==0 );
+  assert( argc>=3 );
+  zDb = argv[2];
+  for(i=3; i<argc; i++){
+    char *z = argv[i];
+    if( z[0]!='-' ) fatalError("unknown argument: \"%s\"", z);
+    if( z[1]=='-' ) z++;
+    fatalError("unknown option: \"%s\"", argv[i]);
+  }
+  rc = sqlite3_open(zDb, &db);
+  if( rc ){
+    fatalError("cannot open database \"%s\": %s", zDb, sqlite3_errmsg(db));
+  }
+  zSql = sqlite3_mprintf(
+    "SELECT count(*), min(length(v)), max(length(v)), avg(length(v))"
+    "  FROM kv"
+  );
+  rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
+  if( rc ) fatalError("cannot prepare SQL [%s]: %s", zSql, sqlite3_errmsg(db));
+  sqlite3_free(zSql);
+  if( sqlite3_step(pStmt)==SQLITE_ROW ){
+    printf("Number of entries:  %8d\n", sqlite3_column_int(pStmt, 0));
+    printf("Average value size: %8d\n", sqlite3_column_int(pStmt, 3));
+    printf("Minimum value size: %8d\n", sqlite3_column_int(pStmt, 1));
+    printf("Maximum value size: %8d\n", sqlite3_column_int(pStmt, 2));
+  }else{
+    printf("No rows\n");
+  }
+  sqlite3_finalize(pStmt);
+  zSql = sqlite3_mprintf("PRAGMA page_size");
+  rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
+  if( rc ) fatalError("cannot prepare SQL [%s]: %s", zSql, sqlite3_errmsg(db));
+  sqlite3_free(zSql);
+  if( sqlite3_step(pStmt)==SQLITE_ROW ){
+    printf("Page-size:          %8d\n", sqlite3_column_int(pStmt, 0));
+  }
+  sqlite3_finalize(pStmt);
+  zSql = sqlite3_mprintf("PRAGMA page_count");
+  rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
+  if( rc ) fatalError("cannot prepare SQL [%s]: %s", zSql, sqlite3_errmsg(db));
+  sqlite3_free(zSql);
+  if( sqlite3_step(pStmt)==SQLITE_ROW ){
+    printf("Page-count:         %8d\n", sqlite3_column_int(pStmt, 0));
+  }
+  sqlite3_finalize(pStmt);
+  sqlite3_close(db);
+  return 0;
+}
+
 /*
 ** Implementation of the "writefile(X,Y)" SQL function.  The argument Y
 ** is written into file X.  The number of bytes written is returned.  Or
@@ -801,6 +872,9 @@ int main(int argc, char **argv){
   if( strcmp(argv[1],"run")==0 ){
     return runMain(argc, argv);
   }
+  if( strcmp(argv[1],"stat")==0 ){
+    return statMain(argc, argv);
+  }
   showHelp();
   return 0;
 }
diff --git a/tool/kvtest-speed.sh b/tool/kvtest-speed.sh
new file mode 100644 (file)
index 0000000..8dc852b
--- /dev/null
@@ -0,0 +1,36 @@
+#!/bin/bash
+#
+# A script for running speed tests using kvtest.
+#
+# The test database must be set up first.  Recommended
+# command-line:
+#
+#    ./kvtest init kvtest.db --count 100K --size 12K --variance 5K
+
+if test "$1" = ""
+then
+  echo "Usage: $0 OUTPUTFILE [OPTIONS]"
+  exit
+fi
+NAME=$1
+shift
+OPTS="-DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_DIRECT_OVERFLOW_READ -DUSE_PREAD"
+KVARGS="--count 100K --stats"
+gcc -g -Os -I. $OPTS $* kvtest.c sqlite3.c -o kvtest
+
+# First run using SQL
+rm cachegrind.out.[1-9][0-9]*
+valgrind --tool=cachegrind ./kvtest run kvtest.db $KVARGS 2>&1 | tee summary-kvtest-$NAME.txt
+mv cachegrind.out.[1-9][0-9]* cachegrind.out.$NAME
+cg_anno.tcl cachegrind.out.$NAME >cout-kvtest-sql-$NAME.txt
+
+# Second run using the sqlite3_blob object
+rm cachegrind.out.[1-9][0-9]*
+valgrind --tool=cachegrind ./kvtest run kvtest.db $KVARGS --blob-api 2>&1 | tee -a summary-kvtest-$NAME.txt
+mv cachegrind.out.[1-9][0-9]* cachegrind.out.$NAME
+cg_anno.tcl cachegrind.out.$NAME >cout-kvtest-$NAME.txt
+
+# Diff the sqlite3_blob API analysis for non-trunk runs.
+if test "$NAME" != "trunk"; then
+  fossil test-diff --tk cout-kvtest-trunk.txt cout-kvtest-$NAME.txt &
+fi