CINXE.COM

SQLite: Artifact [6e022840]

<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <base href="https://www.sqlite.org/src/doc/6937986a/test/kvtest.c"> <meta http-equiv="Content-Security-Policy" content="default-src 'self' data:; script-src 'self' 'nonce-63ab1b7962a683f77e79639b015c2da8563164c3c2252deb'; style-src 'self' 'unsafe-inline'; img-src * data:"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>SQLite: Artifact [6e022840]</title> <link rel="alternate" type="application/rss+xml" title="RSS Feed" href="/src/timeline.rss"> <link rel="stylesheet" href="/src/style.css?id=b1928be2" type="text/css"> </head> <body class="artifact rpage-artifact cpage-artifact"> <header> <div class="title"><h1>SQLite</h1>Artifact [6e022840]</div> <div class="status"> <a href='/src/login'>Login</a> </div> </header> <nav class="mainmenu" title="Main Menu"> <a id='hbbtn' href='/src/sitemap' aria-label='Site Map'>&#9776;</a><a href='https://sqlite.org/' class=''>Home</a> <a href='/src/timeline' class=''>Timeline</a> <a href='/src/dir?ci=trunk' class='desktoponly'>Files</a> <a href='https://sqlite.org/forum/forum' class='desktoponly'>Forum</a> </nav> <nav id="hbdrop" class='hbdrop' title="sitemap"></nav> <form id='f01' method='GET' action='/src/artifact'> <input type='hidden' name='udc' value='1'> <div class="submenu"> <a class="label sml-check-ins-using" href="/src/timeline?uf=6e0228409ea7ca0497dad503fbd109badb5e59545d131014b6aaac68b56f484a">Check-ins Using</a> <a class="label sml-download" href="/src/raw/6e0228409ea7ca0497dad503fbd109badb5e59545d131014b6aaac68b56f484a?at=6e022840">Download</a> <a class="label sml-hex" href="/src/hexdump?name=6e0228409ea7ca0497dad503fbd109badb5e59545d131014b6aaac68b56f484a">Hex</a> <label class='submenuctrl submenuckbox smc-ln'><input type='checkbox' name='ln' id='submenuctrl-0' >Line Numbers</label> </div> <input type="hidden" name="name" value="6e022840"> </form> <div class="content"><span id="debugMsg"></span> <h2>Artifact <span class="nobr"><span class="copy-button" id="copy-hash-ar" data-copytarget="hash-ar" data-copylength="16"></span><span id="hash-ar">6e0228409ea7ca0497dad503fbd109badb5e59545d131014b6aaac68b56f484a</span></span>:</h2> <ul> <li>File <a data-href='/src/finfo?name=test/kvtest.c&ci=6937986a687e4afe&m=6e0228409ea7ca04' href='/src/honeypot'>test/kvtest.c</a> &mdash; part of check-in <a class='timelineHistLink' data-href='/src/info/6937986a687e4afe' href='/src/honeypot'>[6937986a]</a> at <a data-href='/src/timeline?c=2023-06-15+15:43:08' href='/src/honeypot'>2023-06-15 15:43:08</a> on branch <a data-href='/src/timeline?r=trunk' href='/src/honeypot'>trunk</a> &mdash; Fix harmless typo in a comment. (user: <a data-href='/src/timeline?c=2023-06-15+15:43:08&u=drh&y=a' href='/src/honeypot'>drh</a>, size: 35993) <a data-href='/src/annotate?filename=test/kvtest.c&checkin=6937986a687e4afe' href='/src/honeypot'> [annotate]</a> <a data-href='/src/blame?filename=test/kvtest.c&checkin=6937986a687e4afe' href='/src/honeypot'> [blame]</a> <a data-href='/src/timeline?uf=6e0228409ea7ca04' href='/src/honeypot'>[check-ins&nbsp;using]</a> <a data-href='/src/whatis/6e0228409ea7ca04' href='/src/honeypot'>[more...]</a> </ul> <hr> <blockquote class="file-content"> <pre> <code class="language-c">/* ** 2016-12-28 ** ** The author disclaims copyright to this source code. In place of ** a legal notice, here is a blessing: ** ** May you do good and not evil. ** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ************************************************************************* ** ** This file implements &quot;key-value&quot; performance test for SQLite. The ** purpose is to compare the speed of SQLite for accessing large BLOBs ** versus reading those same BLOB values out of individual files in the ** filesystem. ** ** Run &quot;kvtest&quot; with no arguments for on-line help, or see comments below. ** ** HOW TO COMPILE: ** ** (1) Gather this source file and a recent SQLite3 amalgamation with its ** header into the working directory. You should have: ** ** kvtest.c &gt;--- this file ** sqlite3.c \___ SQLite ** sqlite3.h / amlagamation &amp; header ** ** (2) Run you compiler against the two C source code files. ** ** (a) On linux or mac: ** ** OPTS=&quot;-DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION&quot; ** gcc -Os -I. $OPTS kvtest.c sqlite3.c -o kvtest ** ** The $OPTS options can be omitted. The $OPTS merely omit ** the need to link against -ldl and -lpthread, or whatever ** the equivalent libraries are called on your system. ** ** (b) Windows with MSVC: ** ** cl -I. kvtest.c sqlite3.c ** ** USAGE: ** ** (1) Create a test database by running &quot;kvtest init&quot; with appropriate ** options. See the help message for available options. ** ** (2) Construct the corresponding pile-of-files database on disk using ** the &quot;kvtest export&quot; command. ** ** (3) Run tests using &quot;kvtest run&quot; against either the SQLite database or ** the pile-of-files database and with appropriate options. ** ** For example: ** ** ./kvtest init x1.db --count 100000 --size 10000 ** mkdir x1 ** ./kvtest export x1.db x1 ** ./kvtest run x1.db --count 10000 --max-id 1000000 ** ./kvtest run x1 --count 10000 --max-id 1000000 */ static const char zHelp[] = &quot;Usage: kvtest COMMAND ARGS...\n&quot; &quot;\n&quot; &quot; kvtest init DBFILE --count N --size M --pagesize X\n&quot; &quot;\n&quot; &quot; Generate a new test database file named DBFILE containing N\n&quot; &quot; BLOBs each of size M bytes. The page size of the new database\n&quot; &quot; file will be X. Additional options:\n&quot; &quot;\n&quot; &quot; --variance V Randomly vary M by plus or minus V\n&quot; &quot;\n&quot; &quot; kvtest export DBFILE DIRECTORY [--tree]\n&quot; &quot;\n&quot; &quot; Export all the blobs in the kv table of DBFILE into separate\n&quot; &quot; files in DIRECTORY. DIRECTORY is created if it does not previously\n&quot; &quot; exist. If the --tree option is used, then the blobs are written\n&quot; &quot; into a hierarchy of directories, using names like 00/00/00,\n&quot; &quot; 00/00/01, 00/00/02, and so forth. Without the --tree option, all\n&quot; &quot; files are in the top-level directory with names like 000000, 000001,\n&quot; &quot; 000002, and so forth.\n&quot; &quot;\n&quot; &quot; kvtest stat DBFILE [options]\n&quot; &quot;\n&quot; &quot; Display summary information about DBFILE. Options:\n&quot; &quot;\n&quot; &quot; --vacuum Run VACUUM on the database file\n&quot; &quot;\n&quot; &quot; kvtest run DBFILE [options]\n&quot; &quot;\n&quot; &quot; Run a performance test. DBFILE can be either the name of a\n&quot; &quot; database or a directory containing sample files. Options:\n&quot; &quot;\n&quot; &quot; --asc Read blobs in ascending order\n&quot; &quot; --blob-api Use the BLOB API\n&quot; &quot; --cache-size N Database cache size\n&quot; &quot; --count N Read N blobs\n&quot; &quot; --desc Read blobs in descending order\n&quot; &quot; --fsync Synchronous file writes\n&quot; &quot; --integrity-check Run \&quot;PRAGMA integrity_check\&quot; after test\n&quot; &quot; --max-id N Maximum blob key to use\n&quot; &quot; --mmap N Mmap as much as N bytes of DBFILE\n&quot; &quot; --multitrans Each read or write in its own transaction\n&quot; &quot; --nocheckpoint Omit the checkpoint on WAL mode writes\n&quot; &quot; --nosync Set \&quot;PRAGMA synchronous=OFF\&quot;\n&quot; &quot; --jmode MODE Set MODE journal mode prior to starting\n&quot; &quot; --random Read blobs in a random order\n&quot; &quot; --start N Start reading with this blob key\n&quot; &quot; --stats Output operating stats before exiting\n&quot; &quot; --update Do an overwrite test\n&quot; ; /* Reference resources used */ #include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;sys/types.h&gt; #include &lt;sys/stat.h&gt; #include &lt;assert.h&gt; #include &lt;string.h&gt; #include &quot;sqlite3.h&quot; #ifndef _WIN32 # include &lt;unistd.h&gt; #else /* Provide Windows equivalent for the needed parts of unistd.h */ # include &lt;direct.h&gt; # include &lt;io.h&gt; # define R_OK 2 # define S_ISREG(m) (((m) &amp; S_IFMT) == S_IFREG) # define S_ISDIR(m) (((m) &amp; S_IFMT) == S_IFDIR) # define access _access #endif #if !defined(_MSC_VER) # include &lt;stdint.h&gt; #endif /* ** The following macros are used to cast pointers to integers and ** integers to pointers. The way you do this varies from one compiler ** to the next, so we have developed the following set of #if statements ** to generate appropriate macros for a wide range of compilers. ** ** The correct &quot;ANSI&quot; way to do this is to use the intptr_t type. ** Unfortunately, that typedef is not available on all compilers, or ** if it is available, it requires an #include of specific headers ** that vary from one machine to the next. ** ** Ticket #3860: The llvm-gcc-4.2 compiler from Apple chokes on ** the ((void*)&amp;((char*)0)[X]) construct. But MSVC chokes on ((void*)(X)). ** So we have to define the macros in different ways depending on the ** compiler. */ #if defined(__PTRDIFF_TYPE__) /* This case should work for GCC */ # define SQLITE_INT_TO_PTR(X) ((void*)(__PTRDIFF_TYPE__)(X)) # define SQLITE_PTR_TO_INT(X) ((sqlite3_int64)(__PTRDIFF_TYPE__)(X)) #else # define SQLITE_INT_TO_PTR(X) ((void*)(intptr_t)(X)) # define SQLITE_PTR_TO_INT(X) ((sqlite3_int64)(intptr_t)(X)) #endif /* ** Show the help text and quit. */ static void showHelp(void){ fprintf(stdout, &quot;%s&quot;, zHelp); exit(1); } /* ** Show an error message an quit. */ static void fatalError(const char *zFormat, ...){ va_list ap; fprintf(stdout, &quot;ERROR: &quot;); va_start(ap, zFormat); vfprintf(stdout, zFormat, ap); va_end(ap); fprintf(stdout, &quot;\n&quot;); exit(1); } /* ** Return the value of a hexadecimal digit. Return -1 if the input ** is not a hex digit. */ static int hexDigitValue(char c){ if( c&gt;=&#39;0&#39; &amp;&amp; c&lt;=&#39;9&#39; ) return c - &#39;0&#39;; if( c&gt;=&#39;a&#39; &amp;&amp; c&lt;=&#39;f&#39; ) return c - &#39;a&#39; + 10; if( c&gt;=&#39;A&#39; &amp;&amp; c&lt;=&#39;F&#39; ) return c - &#39;A&#39; + 10; return -1; } /* ** Interpret zArg as an integer value, possibly with suffixes. */ static int integerValue(const char *zArg){ int v = 0; static const struct { char *zSuffix; int iMult; } aMult[] = { { &quot;KiB&quot;, 1024 }, { &quot;MiB&quot;, 1024*1024 }, { &quot;GiB&quot;, 1024*1024*1024 }, { &quot;KB&quot;, 1000 }, { &quot;MB&quot;, 1000000 }, { &quot;GB&quot;, 1000000000 }, { &quot;K&quot;, 1000 }, { &quot;M&quot;, 1000000 }, { &quot;G&quot;, 1000000000 }, }; int i; int isNeg = 0; if( zArg[0]==&#39;-&#39; ){ isNeg = 1; zArg++; }else if( zArg[0]==&#39;+&#39; ){ zArg++; } if( zArg[0]==&#39;0&#39; &amp;&amp; zArg[1]==&#39;x&#39; ){ int x; zArg += 2; while( (x = hexDigitValue(zArg[0]))&gt;=0 ){ v = (v&lt;&lt;4) + x; zArg++; } }else{ while( zArg[0]&gt;=&#39;0&#39; &amp;&amp; zArg[0]&lt;=&#39;9&#39; ){ v = v*10 + zArg[0] - &#39;0&#39;; zArg++; } } for(i=0; i&lt;sizeof(aMult)/sizeof(aMult[0]); i++){ if( sqlite3_stricmp(aMult[i].zSuffix, zArg)==0 ){ v *= aMult[i].iMult; break; } } return isNeg? -v : v; } /* ** Check the filesystem object zPath. Determine what it is: ** ** PATH_DIR A single directory holding many files ** PATH_TREE A directory hierarchy with files at the leaves ** PATH_DB An SQLite database ** PATH_NEXIST Does not exist ** PATH_OTHER Something else ** ** PATH_DIR means all of the separate files are grouped together ** into a single directory with names like 000000, 000001, 000002, and ** so forth. PATH_TREE means there is a hierarchy of directories so ** that no single directory has too many entries. The files have names ** like 00/00/00, 00/00/01, 00/00/02 and so forth. The decision between ** PATH_DIR and PATH_TREE is determined by the presence of a subdirectory ** named &quot;00&quot; at the top-level. */ #define PATH_DIR 1 #define PATH_TREE 2 #define PATH_DB 3 #define PATH_NEXIST 0 #define PATH_OTHER 99 static int pathType(const char *zPath){ struct stat x; int rc; if( access(zPath,R_OK) ) return PATH_NEXIST; memset(&amp;x, 0, sizeof(x)); rc = stat(zPath, &amp;x); if( rc&lt;0 ) return PATH_OTHER; if( S_ISDIR(x.st_mode) ){ char *zLayer1 = sqlite3_mprintf(&quot;%s/00&quot;, zPath); memset(&amp;x, 0, sizeof(x)); rc = stat(zLayer1, &amp;x); sqlite3_free(zLayer1); if( rc&lt;0 ) return PATH_DIR; if( S_ISDIR(x.st_mode) ) return PATH_TREE; return PATH_DIR; } if( (x.st_size%512)==0 ) return PATH_DB; return PATH_OTHER; } /* ** Return the size of a file in bytes. Or return -1 if the ** named object is not a regular file or does not exist. */ static sqlite3_int64 fileSize(const char *zPath){ struct stat x; int rc; memset(&amp;x, 0, sizeof(x)); rc = stat(zPath, &amp;x); if( rc&lt;0 ) return -1; if( !S_ISREG(x.st_mode) ) return -1; return x.st_size; } /* ** A Pseudo-random number generator with a fixed seed. Use this so ** that the same sequence of &quot;random&quot; numbers are generated on each ** run, for repeatability. */ static unsigned int randInt(void){ static unsigned int x = 0x333a13cd; static unsigned int y = 0xecb2adea; x = (x&gt;&gt;1) ^ ((1+~(x&amp;1)) &amp; 0xd0000001); y = y*1103515245 + 12345; return x^y; } /* ** Do database initialization. */ static int initMain(int argc, char **argv){ char *zDb; int i, rc; int nCount = 1000; int sz = 10000; int iVariance = 0; int pgsz = 4096; sqlite3 *db; char *zSql; char *zErrMsg = 0; assert( strcmp(argv[1],&quot;init&quot;)==0 ); assert( argc&gt;=3 ); zDb = argv[2]; for(i=3; i&lt;argc; i++){ char *z = argv[i]; if( z[0]!=&#39;-&#39; ) fatalError(&quot;unknown argument: \&quot;%s\&quot;&quot;, z); if( z[1]==&#39;-&#39; ) z++; if( strcmp(z, &quot;-count&quot;)==0 ){ if( i==argc-1 ) fatalError(&quot;missing argument on \&quot;%s\&quot;&quot;, argv[i]); nCount = integerValue(argv[++i]); if( nCount&lt;1 ) fatalError(&quot;the --count must be positive&quot;); continue; } if( strcmp(z, &quot;-size&quot;)==0 ){ if( i==argc-1 ) fatalError(&quot;missing argument on \&quot;%s\&quot;&quot;, argv[i]); sz = integerValue(argv[++i]); if( sz&lt;1 ) fatalError(&quot;the --size must be positive&quot;); continue; } if( strcmp(z, &quot;-variance&quot;)==0 ){ if( i==argc-1 ) fatalError(&quot;missing argument on \&quot;%s\&quot;&quot;, argv[i]); iVariance = integerValue(argv[++i]); continue; } if( strcmp(z, &quot;-pagesize&quot;)==0 ){ if( i==argc-1 ) fatalError(&quot;missing argument on \&quot;%s\&quot;&quot;, argv[i]); pgsz = integerValue(argv[++i]); if( pgsz&lt;512 || pgsz&gt;65536 || ((pgsz-1)&amp;pgsz)!=0 ){ fatalError(&quot;the --pagesize must be power of 2 between 512 and 65536&quot;); } continue; } fatalError(&quot;unknown option: \&quot;%s\&quot;&quot;, argv[i]); } rc = sqlite3_open(zDb, &amp;db); if( rc ){ fatalError(&quot;cannot open database \&quot;%s\&quot;: %s&quot;, zDb, sqlite3_errmsg(db)); } zSql = sqlite3_mprintf( &quot;DROP TABLE IF EXISTS kv;\n&quot; &quot;PRAGMA page_size=%d;\n&quot; &quot;VACUUM;\n&quot; &quot;BEGIN;\n&quot; &quot;CREATE TABLE kv(k INTEGER PRIMARY KEY, v BLOB);\n&quot; &quot;WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x&lt;%d)&quot; &quot; INSERT INTO kv(k,v) SELECT x, randomblob(%d+(random()%%(%d))) FROM c;\n&quot; &quot;COMMIT;\n&quot;, pgsz, nCount, sz, iVariance+1 ); rc = sqlite3_exec(db, zSql, 0, 0, &amp;zErrMsg); if( rc ) fatalError(&quot;database create failed: %s&quot;, zErrMsg); sqlite3_free(zSql); sqlite3_close(db); 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; int doVacuum = 0; assert( strcmp(argv[1],&quot;stat&quot;)==0 ); assert( argc&gt;=3 ); zDb = argv[2]; for(i=3; i&lt;argc; i++){ char *z = argv[i]; if( z[0]!=&#39;-&#39; ) fatalError(&quot;unknown argument: \&quot;%s\&quot;&quot;, z); if( z[1]==&#39;-&#39; ) z++; if( strcmp(z, &quot;-vacuum&quot;)==0 ){ doVacuum = 1; continue; } fatalError(&quot;unknown option: \&quot;%s\&quot;&quot;, argv[i]); } rc = sqlite3_open(zDb, &amp;db); if( rc ){ fatalError(&quot;cannot open database \&quot;%s\&quot;: %s&quot;, zDb, sqlite3_errmsg(db)); } if( doVacuum ){ printf(&quot;Vacuuming....&quot;); fflush(stdout); sqlite3_exec(db, &quot;VACUUM&quot;, 0, 0, 0); printf(&quot; done\n&quot;); } zSql = sqlite3_mprintf( &quot;SELECT count(*), min(length(v)), max(length(v)), avg(length(v))&quot; &quot; FROM kv&quot; ); rc = sqlite3_prepare_v2(db, zSql, -1, &amp;pStmt, 0); if( rc ) fatalError(&quot;cannot prepare SQL [%s]: %s&quot;, zSql, sqlite3_errmsg(db)); sqlite3_free(zSql); if( sqlite3_step(pStmt)==SQLITE_ROW ){ printf(&quot;Number of entries: %8d\n&quot;, sqlite3_column_int(pStmt, 0)); printf(&quot;Average value size: %8d\n&quot;, sqlite3_column_int(pStmt, 3)); printf(&quot;Minimum value size: %8d\n&quot;, sqlite3_column_int(pStmt, 1)); printf(&quot;Maximum value size: %8d\n&quot;, sqlite3_column_int(pStmt, 2)); }else{ printf(&quot;No rows\n&quot;); } sqlite3_finalize(pStmt); zSql = sqlite3_mprintf(&quot;PRAGMA page_size&quot;); rc = sqlite3_prepare_v2(db, zSql, -1, &amp;pStmt, 0); if( rc ) fatalError(&quot;cannot prepare SQL [%s]: %s&quot;, zSql, sqlite3_errmsg(db)); sqlite3_free(zSql); if( sqlite3_step(pStmt)==SQLITE_ROW ){ printf(&quot;Page-size: %8d\n&quot;, sqlite3_column_int(pStmt, 0)); } sqlite3_finalize(pStmt); zSql = sqlite3_mprintf(&quot;PRAGMA page_count&quot;); rc = sqlite3_prepare_v2(db, zSql, -1, &amp;pStmt, 0); if( rc ) fatalError(&quot;cannot prepare SQL [%s]: %s&quot;, zSql, sqlite3_errmsg(db)); sqlite3_free(zSql); if( sqlite3_step(pStmt)==SQLITE_ROW ){ printf(&quot;Page-count: %8d\n&quot;, sqlite3_column_int(pStmt, 0)); } sqlite3_finalize(pStmt); zSql = sqlite3_mprintf(&quot;PRAGMA freelist_count&quot;); rc = sqlite3_prepare_v2(db, zSql, -1, &amp;pStmt, 0); if( rc ) fatalError(&quot;cannot prepare SQL [%s]: %s&quot;, zSql, sqlite3_errmsg(db)); sqlite3_free(zSql); if( sqlite3_step(pStmt)==SQLITE_ROW ){ printf(&quot;Freelist-count: %8d\n&quot;, sqlite3_column_int(pStmt, 0)); } sqlite3_finalize(pStmt); rc = sqlite3_prepare_v2(db, &quot;PRAGMA integrity_check(10)&quot;, -1, &amp;pStmt, 0); if( rc ) fatalError(&quot;cannot prepare integrity check: %s&quot;, sqlite3_errmsg(db)); while( sqlite3_step(pStmt)==SQLITE_ROW ){ printf(&quot;Integrity-check: %s\n&quot;, sqlite3_column_text(pStmt, 0)); } sqlite3_finalize(pStmt); sqlite3_close(db); return 0; } /* ** remember(V,PTR) ** ** Return the integer value V. Also save the value of V in a ** C-language variable whose address is PTR. */ static void rememberFunc( sqlite3_context *pCtx, int argc, sqlite3_value **argv ){ sqlite3_int64 v; sqlite3_int64 ptr; assert( argc==2 ); v = sqlite3_value_int64(argv[0]); ptr = sqlite3_value_int64(argv[1]); *(sqlite3_int64*)SQLITE_INT_TO_PTR(ptr) = v; sqlite3_result_int64(pCtx, v); } /* ** Make sure a directory named zDir exists. */ static void kvtest_mkdir(const char *zDir){ #if defined(_WIN32) (void)mkdir(zDir); #else (void)mkdir(zDir, 0755); #endif } /* ** Export the kv table to individual files in the filesystem */ static int exportMain(int argc, char **argv){ char *zDb; char *zDir; sqlite3 *db; sqlite3_stmt *pStmt; int rc; int ePathType; int nFN; char *zFN; char *zTail; size_t nWrote; int i; assert( strcmp(argv[1],&quot;export&quot;)==0 ); assert( argc&gt;=3 ); if( argc&lt;4 ) fatalError(&quot;Usage: kvtest export DATABASE DIRECTORY [OPTIONS]&quot;); zDb = argv[2]; zDir = argv[3]; kvtest_mkdir(zDir); for(i=4; i&lt;argc; i++){ const char *z = argv[i]; if( z[0]==&#39;-&#39; &amp;&amp; z[1]==&#39;-&#39; ) z++; if( strcmp(z,&quot;-tree&quot;)==0 ){ zFN = sqlite3_mprintf(&quot;%s/00&quot;, zDir); kvtest_mkdir(zFN); sqlite3_free(zFN); continue; } fatalError(&quot;unknown argument: \&quot;%s\&quot;\n&quot;, argv[i]); } ePathType = pathType(zDir); if( ePathType!=PATH_DIR &amp;&amp; ePathType!=PATH_TREE ){ fatalError(&quot;object \&quot;%s\&quot; is not a directory&quot;, zDir); } rc = sqlite3_open(zDb, &amp;db); if( rc ){ fatalError(&quot;cannot open database \&quot;%s\&quot;: %s&quot;, zDb, sqlite3_errmsg(db)); } rc = sqlite3_prepare_v2(db, &quot;SELECT k, v FROM kv ORDER BY k&quot;, -1, &amp;pStmt, 0); if( rc ){ fatalError(&quot;prepare_v2 failed: %s\n&quot;, sqlite3_errmsg(db)); } nFN = (int)strlen(zDir); zFN = sqlite3_mprintf(&quot;%s/00/00/00.extra---------------------&quot;, zDir); if( zFN==0 ){ fatalError(&quot;malloc failed\n&quot;); } zTail = zFN + nFN + 1; while( sqlite3_step(pStmt)==SQLITE_ROW ){ int iKey = sqlite3_column_int(pStmt, 0); sqlite3_int64 nData = sqlite3_column_bytes(pStmt, 1); const void *pData = sqlite3_column_blob(pStmt, 1); FILE *out; if( ePathType==PATH_DIR ){ sqlite3_snprintf(20, zTail, &quot;%06d&quot;, iKey); }else{ sqlite3_snprintf(20, zTail, &quot;%02d&quot;, iKey/10000); kvtest_mkdir(zFN); sqlite3_snprintf(20, zTail, &quot;%02d/%02d&quot;, iKey/10000, (iKey/100)%100); kvtest_mkdir(zFN); sqlite3_snprintf(20, zTail, &quot;%02d/%02d/%02d&quot;, iKey/10000, (iKey/100)%100, iKey%100); } out = fopen(zFN, &quot;wb&quot;); nWrote = fwrite(pData, 1, (size_t)nData, out); fclose(out); printf(&quot;\r%s &quot;, zTail); fflush(stdout); if( nWrote!=(size_t)nData ){ fatalError(&quot;Wrote only %d of %d bytes to %s\n&quot;, (int)nWrote, nData, zFN); } } sqlite3_finalize(pStmt); sqlite3_close(db); sqlite3_free(zFN); printf(&quot;\n&quot;); return 0; } /* ** Read the content of file zName into memory obtained from sqlite3_malloc64() ** and return a pointer to the buffer. The caller is responsible for freeing ** the memory. ** ** If parameter pnByte is not NULL, (*pnByte) is set to the number of bytes ** read. ** ** For convenience, a nul-terminator byte is always appended to the data read ** from the file before the buffer is returned. This byte is not included in ** the final value of (*pnByte), if applicable. ** ** NULL is returned if any error is encountered. The final value of *pnByte ** is undefined in this case. */ static unsigned char *readFile(const char *zName, sqlite3_int64 *pnByte){ FILE *in; /* FILE from which to read content of zName */ sqlite3_int64 nIn; /* Size of zName in bytes */ size_t nRead; /* Number of bytes actually read */ unsigned char *pBuf; /* Content read from disk */ nIn = fileSize(zName); if( nIn&lt;0 ) return 0; in = fopen(zName, &quot;rb&quot;); if( in==0 ) return 0; pBuf = sqlite3_malloc64( nIn ); if( pBuf==0 ) return 0; nRead = fread(pBuf, (size_t)nIn, 1, in); fclose(in); if( nRead!=1 ){ sqlite3_free(pBuf); return 0; } if( pnByte ) *pnByte = nIn; return pBuf; } /* ** Overwrite a file with randomness. Do not change the size of the ** file. */ static void updateFile(const char *zName, sqlite3_int64 *pnByte, int doFsync){ FILE *out; /* FILE from which to read content of zName */ sqlite3_int64 sz; /* Size of zName in bytes */ size_t nWritten; /* Number of bytes actually read */ unsigned char *pBuf; /* Content to store on disk */ const char *zMode = &quot;wb&quot;; /* Mode for fopen() */ sz = fileSize(zName); if( sz&lt;0 ){ fatalError(&quot;No such file: \&quot;%s\&quot;&quot;, zName); } *pnByte = sz; if( sz==0 ) return; pBuf = sqlite3_malloc64( sz ); if( pBuf==0 ){ fatalError(&quot;Cannot allocate %lld bytes\n&quot;, sz); } sqlite3_randomness((int)sz, pBuf); #if defined(_WIN32) if( doFsync ) zMode = &quot;wbc&quot;; #endif out = fopen(zName, zMode); if( out==0 ){ fatalError(&quot;Cannot open \&quot;%s\&quot; for writing\n&quot;, zName); } nWritten = fwrite(pBuf, 1, (size_t)sz, out); if( doFsync ){ #if defined(_WIN32) fflush(out); #else fsync(fileno(out)); #endif } fclose(out); if( nWritten!=(size_t)sz ){ fatalError(&quot;Wrote only %d of %d bytes to \&quot;%s\&quot;\n&quot;, (int)nWritten, (int)sz, zName); } sqlite3_free(pBuf); } /* ** Return the current time in milliseconds since the beginning of ** the Julian epoch. */ static sqlite3_int64 timeOfDay(void){ static sqlite3_vfs *clockVfs = 0; sqlite3_int64 t; if( clockVfs==0 ) clockVfs = sqlite3_vfs_find(0); if( clockVfs-&gt;iVersion&gt;=2 &amp;&amp; clockVfs-&gt;xCurrentTimeInt64!=0 ){ clockVfs-&gt;xCurrentTimeInt64(clockVfs, &amp;t); }else{ double r; clockVfs-&gt;xCurrentTime(clockVfs, &amp;r); t = (sqlite3_int64)(r*86400000.0); } 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, &quot;/proc/%d/io&quot;, getpid()); in = fopen(z, &quot;rb&quot;); if( in==0 ) return; while( fgets(z, sizeof(z), in)!=0 ){ static const struct { const char *zPattern; const char *zDesc; } aTrans[] = { { &quot;rchar: &quot;, &quot;Bytes received by read():&quot; }, { &quot;wchar: &quot;, &quot;Bytes sent to write():&quot; }, { &quot;syscr: &quot;, &quot;Read() system calls:&quot; }, { &quot;syscw: &quot;, &quot;Write() system calls:&quot; }, { &quot;read_bytes: &quot;, &quot;Bytes read from storage:&quot; }, { &quot;write_bytes: &quot;, &quot;Bytes written to storage:&quot; }, { &quot;cancelled_write_bytes: &quot;, &quot;Cancelled write bytes:&quot; }, }; int i; for(i=0; i&lt;sizeof(aTrans)/sizeof(aTrans[0]); i++){ int n = (int)strlen(aTrans[i].zPattern); if( strncmp(aTrans[i].zPattern, z, n)==0 ){ fprintf(out, &quot;%-36s %s&quot;, aTrans[i].zDesc, &amp;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, &quot;\n&quot;); iHiwtr = iCur = -1; sqlite3_status(SQLITE_STATUS_MEMORY_USED, &amp;iCur, &amp;iHiwtr, bReset); fprintf(out, &quot;Memory Used: %d (max %d) bytes\n&quot;, iCur, iHiwtr); iHiwtr = iCur = -1; sqlite3_status(SQLITE_STATUS_MALLOC_COUNT, &amp;iCur, &amp;iHiwtr, bReset); fprintf(out, &quot;Number of Outstanding Allocations: %d (max %d)\n&quot;, iCur, iHiwtr); iHiwtr = iCur = -1; sqlite3_status(SQLITE_STATUS_PAGECACHE_USED, &amp;iCur, &amp;iHiwtr, bReset); fprintf(out, &quot;Number of Pcache Pages Used: %d (max %d) pages\n&quot;, iCur, iHiwtr); iHiwtr = iCur = -1; sqlite3_status(SQLITE_STATUS_PAGECACHE_OVERFLOW, &amp;iCur, &amp;iHiwtr, bReset); fprintf(out, &quot;Number of Pcache Overflow Bytes: %d (max %d) bytes\n&quot;, iCur, iHiwtr); iHiwtr = iCur = -1; sqlite3_status(SQLITE_STATUS_MALLOC_SIZE, &amp;iCur, &amp;iHiwtr, bReset); fprintf(out, &quot;Largest Allocation: %d bytes\n&quot;, iHiwtr); iHiwtr = iCur = -1; sqlite3_status(SQLITE_STATUS_PAGECACHE_SIZE, &amp;iCur, &amp;iHiwtr, bReset); fprintf(out, &quot;Largest Pcache Allocation: %d bytes\n&quot;, iHiwtr); iHiwtr = iCur = -1; sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_USED, &amp;iCur, &amp;iHiwtr, bReset); fprintf(out, &quot;Pager Heap Usage: %d bytes\n&quot;, iCur); iHiwtr = iCur = -1; sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_HIT, &amp;iCur, &amp;iHiwtr, 1); fprintf(out, &quot;Page cache hits: %d\n&quot;, iCur); iHiwtr = iCur = -1; sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_MISS, &amp;iCur, &amp;iHiwtr, 1); fprintf(out, &quot;Page cache misses: %d\n&quot;, iCur); iHiwtr = iCur = -1; sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_WRITE, &amp;iCur, &amp;iHiwtr, 1); fprintf(out, &quot;Page cache writes: %d\n&quot;, iCur); iHiwtr = iCur = -1; #ifdef __linux__ displayLinuxIoStats(out); #endif return 0; } /* Blob access order */ #define ORDER_ASC 1 #define ORDER_DESC 2 #define ORDER_RANDOM 3 /* ** Run a performance test */ static int runMain(int argc, char **argv){ int eType; /* Is zDb a database or a directory? */ char *zDb; /* Database or directory name */ int i; /* Loop counter */ int rc; /* Return code from SQLite calls */ int nCount = 1000; /* Number of blob fetch operations */ int nExtra = 0; /* Extra cycles */ int iKey = 1; /* Next blob key */ int iMax = 0; /* Largest allowed key */ 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 */ int isUpdateTest = 0; /* Do in-place updates rather than reads */ int doIntegrityCk = 0; /* Run PRAGMA integrity_check after the test */ int noSync = 0; /* Disable synchronous mode */ int doFsync = 0; /* Update disk files synchronously */ int doMultiTrans = 0; /* Each operation in its own transaction */ int noCheckpoint = 0; /* Omit the checkpoint in WAL mode */ sqlite3 *db = 0; /* Database connection */ sqlite3_stmt *pStmt = 0; /* Prepared statement for SQL access */ sqlite3_blob *pBlob = 0; /* Handle for incremental Blob I/O */ sqlite3_int64 tmStart; /* Start time */ sqlite3_int64 tmElapsed; /* Elapsed time */ int mmapSize = 0; /* --mmap N argument */ sqlite3_int64 nData = 0; /* Bytes of data */ sqlite3_int64 nTotal = 0; /* Total data read */ unsigned char *pData = 0; /* Content of the blob */ sqlite3_int64 nAlloc = 0; /* Space allocated for pData[] */ const char *zJMode = 0; /* Journal mode */ assert( strcmp(argv[1],&quot;run&quot;)==0 ); assert( argc&gt;=3 ); zDb = argv[2]; eType = pathType(zDb); if( eType==PATH_OTHER ) fatalError(&quot;unknown object type: \&quot;%s\&quot;&quot;, zDb); if( eType==PATH_NEXIST ) fatalError(&quot;object does not exist: \&quot;%s\&quot;&quot;, zDb); for(i=3; i&lt;argc; i++){ char *z = argv[i]; if( z[0]!=&#39;-&#39; ) fatalError(&quot;unknown argument: \&quot;%s\&quot;&quot;, z); if( z[1]==&#39;-&#39; ) z++; if( strcmp(z, &quot;-asc&quot;)==0 ){ eOrder = ORDER_ASC; continue; } if( strcmp(z, &quot;-blob-api&quot;)==0 ){ bBlobApi = 1; continue; } if( strcmp(z, &quot;-cache-size&quot;)==0 ){ if( i==argc-1 ) fatalError(&quot;missing argument on \&quot;%s\&quot;&quot;, argv[i]); iCache = integerValue(argv[++i]); continue; } if( strcmp(z, &quot;-count&quot;)==0 ){ if( i==argc-1 ) fatalError(&quot;missing argument on \&quot;%s\&quot;&quot;, argv[i]); nCount = integerValue(argv[++i]); if( nCount&lt;1 ) fatalError(&quot;the --count must be positive&quot;); continue; } if( strcmp(z, &quot;-desc&quot;)==0 ){ eOrder = ORDER_DESC; continue; } if( strcmp(z, &quot;-fsync&quot;)==0 ){ doFsync = 1; continue; } if( strcmp(z, &quot;-integrity-check&quot;)==0 ){ doIntegrityCk = 1; continue; } if( strcmp(z, &quot;-jmode&quot;)==0 ){ if( i==argc-1 ) fatalError(&quot;missing argument on \&quot;%s\&quot;&quot;, argv[i]); zJMode = argv[++i]; continue; } if( strcmp(z, &quot;-mmap&quot;)==0 ){ if( i==argc-1 ) fatalError(&quot;missing argument on \&quot;%s\&quot;&quot;, argv[i]); mmapSize = integerValue(argv[++i]); if( nCount&lt;0 ) fatalError(&quot;the --mmap must be non-negative&quot;); continue; } if( strcmp(z, &quot;-max-id&quot;)==0 ){ if( i==argc-1 ) fatalError(&quot;missing argument on \&quot;%s\&quot;&quot;, argv[i]); iMax = integerValue(argv[++i]); continue; } if( strcmp(z, &quot;-multitrans&quot;)==0 ){ doMultiTrans = 1; continue; } if( strcmp(z, &quot;-nocheckpoint&quot;)==0 ){ noCheckpoint = 1; continue; } if( strcmp(z, &quot;-nosync&quot;)==0 ){ noSync = 1; continue; } if( strcmp(z, &quot;-random&quot;)==0 ){ eOrder = ORDER_RANDOM; continue; } if( strcmp(z, &quot;-start&quot;)==0 ){ if( i==argc-1 ) fatalError(&quot;missing argument on \&quot;%s\&quot;&quot;, argv[i]); iKey = integerValue(argv[++i]); if( iKey&lt;1 ) fatalError(&quot;the --start must be positive&quot;); continue; } if( strcmp(z, &quot;-stats&quot;)==0 ){ bStats = 1; continue; } if( strcmp(z, &quot;-update&quot;)==0 ){ isUpdateTest = 1; continue; } fatalError(&quot;unknown option: \&quot;%s\&quot;&quot;, argv[i]); } if( eType==PATH_DB ){ /* Recover any prior crashes prior to starting the timer */ sqlite3_open(zDb, &amp;db); sqlite3_exec(db, &quot;SELECT rowid FROM sqlite_schema LIMIT 1&quot;, 0, 0, 0); sqlite3_close(db); db = 0; } tmStart = timeOfDay(); if( eType==PATH_DB ){ char *zSql; rc = sqlite3_open(zDb, &amp;db); if( rc ){ fatalError(&quot;cannot open database \&quot;%s\&quot;: %s&quot;, zDb, sqlite3_errmsg(db)); } zSql = sqlite3_mprintf(&quot;PRAGMA mmap_size=%d&quot;, mmapSize); sqlite3_exec(db, zSql, 0, 0, 0); sqlite3_free(zSql); zSql = sqlite3_mprintf(&quot;PRAGMA cache_size=%d&quot;, iCache); sqlite3_exec(db, zSql, 0, 0, 0); sqlite3_free(zSql); if( noSync ){ sqlite3_exec(db, &quot;PRAGMA synchronous=OFF&quot;, 0, 0, 0); } pStmt = 0; sqlite3_prepare_v2(db, &quot;PRAGMA page_size&quot;, -1, &amp;pStmt, 0); if( sqlite3_step(pStmt)==SQLITE_ROW ){ iPagesize = sqlite3_column_int(pStmt, 0); } sqlite3_finalize(pStmt); sqlite3_prepare_v2(db, &quot;PRAGMA cache_size&quot;, -1, &amp;pStmt, 0); if( sqlite3_step(pStmt)==SQLITE_ROW ){ iCache = sqlite3_column_int(pStmt, 0); }else{ iCache = 0; } sqlite3_finalize(pStmt); pStmt = 0; if( zJMode ){ zSql = sqlite3_mprintf(&quot;PRAGMA journal_mode=%Q&quot;, zJMode); sqlite3_exec(db, zSql, 0, 0, 0); sqlite3_free(zSql); if( noCheckpoint ){ sqlite3_exec(db, &quot;PRAGMA wal_autocheckpoint=0&quot;, 0, 0, 0); } } sqlite3_prepare_v2(db, &quot;PRAGMA journal_mode&quot;, -1, &amp;pStmt, 0); if( sqlite3_step(pStmt)==SQLITE_ROW ){ zJMode = sqlite3_mprintf(&quot;%s&quot;, sqlite3_column_text(pStmt, 0)); }else{ zJMode = &quot;???&quot;; } sqlite3_finalize(pStmt); if( iMax&lt;=0 ){ sqlite3_prepare_v2(db, &quot;SELECT max(k) FROM kv&quot;, -1, &amp;pStmt, 0); if( sqlite3_step(pStmt)==SQLITE_ROW ){ iMax = sqlite3_column_int(pStmt, 0); } sqlite3_finalize(pStmt); } pStmt = 0; if( !doMultiTrans ) sqlite3_exec(db, &quot;BEGIN&quot;, 0, 0, 0); } if( iMax&lt;=0 ) iMax = 1000; for(i=0; i&lt;nCount; i++){ if( eType==PATH_DIR || eType==PATH_TREE ){ /* CASE 1: Reading or writing blobs out of separate files */ char *zKey; if( eType==PATH_DIR ){ zKey = sqlite3_mprintf(&quot;%s/%06d&quot;, zDb, iKey); }else{ zKey = sqlite3_mprintf(&quot;%s/%02d/%02d/%02d&quot;, zDb, iKey/10000, (iKey/100)%100, iKey%100); } nData = 0; if( isUpdateTest ){ updateFile(zKey, &amp;nData, doFsync); }else{ pData = readFile(zKey, &amp;nData); sqlite3_free(pData); } sqlite3_free(zKey); }else if( bBlobApi ){ /* CASE 2: Reading from database using the incremental BLOB I/O API */ if( pBlob==0 ){ rc = sqlite3_blob_open(db, &quot;main&quot;, &quot;kv&quot;, &quot;v&quot;, iKey, isUpdateTest, &amp;pBlob); if( rc ){ fatalError(&quot;could not open sqlite3_blob handle: %s&quot;, sqlite3_errmsg(db)); } }else{ rc = sqlite3_blob_reopen(pBlob, iKey); } if( rc==SQLITE_OK ){ nData = sqlite3_blob_bytes(pBlob); if( nAlloc&lt;nData+1 ){ nAlloc = nData+100; pData = sqlite3_realloc64(pData, nAlloc); } if( pData==0 ) fatalError(&quot;cannot allocate %d bytes&quot;, nData+1); if( isUpdateTest ){ sqlite3_randomness((int)nData, pData); rc = sqlite3_blob_write(pBlob, pData, (int)nData, 0); if( rc!=SQLITE_OK ){ fatalError(&quot;could not write the blob at %d: %s&quot;, iKey, sqlite3_errmsg(db)); } }else{ rc = sqlite3_blob_read(pBlob, pData, (int)nData, 0); if( rc!=SQLITE_OK ){ fatalError(&quot;could not read the blob at %d: %s&quot;, iKey, sqlite3_errmsg(db)); } } } }else{ /* CASE 3: Reading from database using SQL */ if( pStmt==0 ){ if( isUpdateTest ){ sqlite3_create_function(db, &quot;remember&quot;, 2, SQLITE_UTF8, 0, rememberFunc, 0, 0); rc = sqlite3_prepare_v2(db, &quot;UPDATE kv SET v=randomblob(remember(length(v),?2))&quot; &quot; WHERE k=?1&quot;, -1, &amp;pStmt, 0); sqlite3_bind_int64(pStmt, 2, SQLITE_PTR_TO_INT(&amp;nData)); }else{ rc = sqlite3_prepare_v2(db, &quot;SELECT v FROM kv WHERE k=?1&quot;, -1, &amp;pStmt, 0); } if( rc ){ fatalError(&quot;cannot prepare query: %s&quot;, sqlite3_errmsg(db)); } }else{ sqlite3_reset(pStmt); } sqlite3_bind_int(pStmt, 1, iKey); nData = 0; rc = sqlite3_step(pStmt); if( rc==SQLITE_ROW ){ nData = sqlite3_column_bytes(pStmt, 0); pData = (unsigned char*)sqlite3_column_blob(pStmt, 0); } } if( eOrder==ORDER_ASC ){ iKey++; if( iKey&gt;iMax ) iKey = 1; }else if( eOrder==ORDER_DESC ){ iKey--; if( iKey&lt;=0 ) iKey = iMax; }else{ iKey = (randInt()%iMax)+1; } nTotal += nData; if( nData==0 ){ nCount++; nExtra++; } } if( nAlloc ) sqlite3_free(pData); if( pStmt ) sqlite3_finalize(pStmt); if( pBlob ) sqlite3_blob_close(pBlob); if( bStats ){ display_stats(db, 0); } if( db ){ if( !doMultiTrans ) sqlite3_exec(db, &quot;COMMIT&quot;, 0, 0, 0); if( !noCheckpoint ){ sqlite3_close(db); db = 0; } } tmElapsed = timeOfDay() - tmStart; if( db &amp;&amp; noCheckpoint ){ sqlite3_close(db); db = 0; } if( nExtra ){ printf(&quot;%d cycles due to %d misses\n&quot;, nCount, nExtra); } if( eType==PATH_DB ){ printf(&quot;SQLite version: %s\n&quot;, sqlite3_libversion()); if( doIntegrityCk ){ sqlite3_open(zDb, &amp;db); sqlite3_prepare_v2(db, &quot;PRAGMA integrity_check&quot;, -1, &amp;pStmt, 0); while( sqlite3_step(pStmt)==SQLITE_ROW ){ printf(&quot;integrity-check: %s\n&quot;, sqlite3_column_text(pStmt, 0)); } sqlite3_finalize(pStmt); sqlite3_close(db); db = 0; } } printf(&quot;--count %d --max-id %d&quot;, nCount-nExtra, iMax); switch( eOrder ){ case ORDER_RANDOM: printf(&quot; --random\n&quot;); break; case ORDER_DESC: printf(&quot; --desc\n&quot;); break; default: printf(&quot; --asc\n&quot;); break; } if( eType==PATH_DB ){ printf(&quot;--cache-size %d --jmode %s\n&quot;, iCache, zJMode); printf(&quot;--mmap %d%s\n&quot;, mmapSize, bBlobApi ? &quot; --blob-api&quot; : &quot;&quot;); if( noSync ) printf(&quot;--nosync\n&quot;); } if( iPagesize ) printf(&quot;Database page size: %d\n&quot;, iPagesize); printf(&quot;Total elapsed time: %.3f\n&quot;, tmElapsed/1000.0); if( isUpdateTest ){ printf(&quot;Microseconds per BLOB write: %.3f\n&quot;, tmElapsed*1000.0/nCount); printf(&quot;Content write rate: %.1f MB/s\n&quot;, nTotal/(1000.0*tmElapsed)); }else{ printf(&quot;Microseconds per BLOB read: %.3f\n&quot;, tmElapsed*1000.0/nCount); printf(&quot;Content read rate: %.1f MB/s\n&quot;, nTotal/(1000.0*tmElapsed)); } return 0; } int main(int argc, char **argv){ if( argc&lt;3 ) showHelp(); if( strcmp(argv[1],&quot;init&quot;)==0 ){ return initMain(argc, argv); } if( strcmp(argv[1],&quot;export&quot;)==0 ){ return exportMain(argc, argv); } if( strcmp(argv[1],&quot;run&quot;)==0 ){ return runMain(argc, argv); } if( strcmp(argv[1],&quot;stat&quot;)==0 ){ return statMain(argc, argv); } showHelp(); return 0; } </code> </pre> </blockquote> </div> <footer> This page was generated in about 0.004s by Fossil 2.26 [304503ed24] 2025-02-20 14:48:54 </footer> <script id='href-data' type='text/json'>{"delay":250,"mouseover":1}</script> <script nonce="63ab1b7962a683f77e79639b015c2da8563164c3c2252deb">/* style.c:898 */ function debugMsg(msg){ var n = document.getElementById("debugMsg"); if(n){n.textContent=msg;} } /* href.js */ var antiRobot = 0; function antiRobotGo(){ if( antiRobot!=3 ) return; antiRobot = 7; var anchors = document.getElementsByTagName("a"); for(var i=0; i<anchors.length; i++){ var j = anchors[i]; if(j.hasAttribute("data-href")) j.href=j.getAttribute("data-href"); } var forms = document.getElementsByTagName("form"); for(var i=0; i<forms.length; i++){ var j = forms[i]; if(j.hasAttribute("data-action")) j.action=j.getAttribute("data-action"); } } function antiRobotDefense(){ var x = document.getElementById("href-data"); var jx = x.textContent || x.innerText; var g = JSON.parse(jx); if( g.mouseover ){ document.body.onmousedown=function(){ antiRobot |= 2; antiRobotGo(); document.body.onmousedown=null; } document.body.onmousemove=function(){ antiRobot |= 2; antiRobotGo(); document.body.onmousemove=null; } }else{ antiRobot |= 2; } if( g.delay>0 ){ setTimeout(function(){ antiRobot |= 1; antiRobotGo(); }, g.delay) }else{ antiRobot |= 1; } antiRobotGo(); } antiRobotDefense(); </script> <script nonce='63ab1b7962a683f77e79639b015c2da8563164c3c2252deb'> /* copybtn.js *************************************************************/ function makeCopyButton(idTarget,bFlipped,cchLength){ var elButton = document.createElement("span"); elButton.className = "copy-button"; if( bFlipped ) elButton.className += " copy-button-flipped"; elButton.id = "copy-" + idTarget; initCopyButton(elButton,idTarget,cchLength); return elButton; } function initCopyButtonById(idButton,idTarget,cchLength){ idButton = idButton || "copy-" + idTarget; var elButton = document.getElementById(idButton); if( elButton ) initCopyButton(elButton,idTarget,cchLength); return elButton; } function initCopyButton(elButton,idTarget,cchLength){ elButton.style.transition = ""; elButton.style.opacity = 1; if( idTarget ) elButton.setAttribute("data-copytarget",idTarget); if( cchLength ) elButton.setAttribute("data-copylength",cchLength); elButton.onclick = clickCopyButton; return elButton; } setTimeout(function(){ var elButtons = document.getElementsByClassName("copy-button"); for ( var i=0; i<elButtons.length; i++ ){ initCopyButton(elButtons[i],0,0); } },1); function clickCopyButton(e){ e.preventDefault(); e.stopPropagation(); if( this.getAttribute("data-copylocked") ) return; this.setAttribute("data-copylocked","1"); this.style.transition = "opacity 400ms ease-in-out"; this.style.opacity = 0; var idTarget = this.getAttribute("data-copytarget"); var elTarget = document.getElementById(idTarget); if( elTarget ){ var text = elTarget.innerText.replace(/^\s+|\s+$/g,""); var cchLength = parseInt(this.getAttribute("data-copylength")); if( !isNaN(cchLength) && cchLength>0 ){ text = text.slice(0,cchLength); } copyTextToClipboard(text); } setTimeout(function(){ this.style.transition = ""; this.style.opacity = 1; this.removeAttribute("data-copylocked"); }.bind(this),400); } function copyTextToClipboard(text){ if( window.clipboardData && window.clipboardData.setData ){ window.clipboardData.setData("Text",text); }else{ var elTextarea = document.createElement("textarea"); elTextarea.style.position = "fixed"; elTextarea.value = text; document.body.appendChild(elTextarea); elTextarea.select(); try{ document.execCommand("copy"); }catch(err){ }finally{ document.body.removeChild(elTextarea); } } } /* hbmenu.js *************************************************************/ (function() { var hbButton = document.getElementById("hbbtn"); if (!hbButton) return; if (!document.addEventListener) return; var panel = document.getElementById("hbdrop"); if (!panel) return; if (!panel.style) return; var panelBorder = panel.style.border; var panelInitialized = false; var panelResetBorderTimerID = 0; var animate = panel.style.transition !== null && (typeof(panel.style.transition) == "string"); var animMS = panel.getAttribute("data-anim-ms"); if (animMS) { animMS = parseInt(animMS); if (isNaN(animMS) || animMS == 0) animate = false; else if (animMS < 0) animMS = 400; } else animMS = 400; var panelHeight; function calculatePanelHeight() { panel.style.maxHeight = ''; var es = window.getComputedStyle(panel), edis = es.display, epos = es.position, evis = es.visibility; panel.style.visibility = 'hidden'; panel.style.position = 'absolute'; panel.style.display = 'block'; panelHeight = panel.offsetHeight + 'px'; panel.style.display = edis; panel.style.position = epos; panel.style.visibility = evis; } function showPanel() { if (panelResetBorderTimerID) { clearTimeout(panelResetBorderTimerID); panelResetBorderTimerID = 0; } if (animate) { if (!panelInitialized) { panelInitialized = true; calculatePanelHeight(); panel.style.transition = 'max-height ' + animMS + 'ms ease-in-out'; panel.style.overflowY = 'hidden'; panel.style.maxHeight = '0'; } setTimeout(function() { panel.style.maxHeight = panelHeight; panel.style.border = panelBorder; }, 40); } panel.style.display = 'block'; document.addEventListener('keydown',panelKeydown,true); document.addEventListener('click',panelClick,false); } var panelKeydown = function(event) { var key = event.which || event.keyCode; if (key == 27) { event.stopPropagation(); panelToggle(true); } }; var panelClick = function(event) { if (!panel.contains(event.target)) { panelToggle(true); } }; function panelShowing() { if (animate) { return panel.style.maxHeight == panelHeight; } else { return panel.style.display == 'block'; } } function hasChildren(element) { var childElement = element.firstChild; while (childElement) { if (childElement.nodeType == 1) return true; childElement = childElement.nextSibling; } return false; } window.addEventListener('resize',function(event) { panelInitialized = false; },false); hbButton.addEventListener('click',function(event) { event.stopPropagation(); event.preventDefault(); panelToggle(false); },false); function panelToggle(suppressAnimation) { if (panelShowing()) { document.removeEventListener('keydown',panelKeydown,true); document.removeEventListener('click',panelClick,false); if (animate) { if (suppressAnimation) { var transition = panel.style.transition; panel.style.transition = ''; panel.style.maxHeight = '0'; panel.style.border = 'none'; setTimeout(function() { panel.style.transition = transition; }, 40); } else { panel.style.maxHeight = '0'; panelResetBorderTimerID = setTimeout(function() { panel.style.border = 'none'; panelResetBorderTimerID = 0; }, animMS); } } else { panel.style.display = 'none'; } } else { if (!hasChildren(panel)) { var xhr = new XMLHttpRequest(); xhr.onload = function() { var doc = xhr.responseXML; if (doc) { var sm = doc.querySelector("ul#sitemap"); if (sm && xhr.status == 200) { panel.innerHTML = sm.outerHTML; showPanel(); } } } var url = hbButton.href + (hbButton.href.includes("?")?"&popup":"?popup") xhr.open("GET", url); xhr.responseType = "document"; xhr.send(); } else { showPanel(); } } } })(); /* menu.js *************************************************************/ function toggle_annotation_log(){ var w = document.getElementById("annotation_log"); var x = document.forms["f01"].elements["log"].checked w.style.display = x ? "block" : "none"; } function submenu_onchange_submit(){ var w = document.getElementById("f01"); w.submit(); } (function (){ for(var i=0; 1; i++){ var x = document.getElementById("submenuctrl-"+i); if(!x) break; if( !x.hasAttribute('data-ctrl') ){ x.onchange = submenu_onchange_submit; }else{ var cx = x.getAttribute('data-ctrl'); if( cx=="toggle_annotation_log" ){ x.onchange = toggle_annotation_log; } } } })(); </script> </body> </html>

Pages: 1 2 3 4 5 6 7 8 9 10