1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-07 02:42:48 +03:00

New speed testing tools. (CVS 5786)

FossilOrigin-Name: 2d427746d53104ca032c404f7f65c51b41b7a20e
This commit is contained in:
drh
2008-10-09 17:57:33 +00:00
parent da81eab599
commit 5eddafeb64
4 changed files with 245 additions and 98 deletions

View File

@@ -90,89 +90,6 @@ static void prepareAndRun(sqlite3 *db, const char *zSql, int bQuiet){
}
}
/***************************************************************************
** The "overwrite" VFS is an overlay over the default VFS. It modifies
** the xTruncate operation on journal files so that xTruncate merely
** writes zeros into the first 50 bytes of the file rather than truely
** truncating the file.
**
** The following variables are initialized to be the virtual function
** tables for the overwrite VFS.
*/
static sqlite3_vfs overwrite_vfs;
static sqlite3_io_methods overwrite_methods;
/*
** The truncate method for journal files in the overwrite VFS.
*/
static int overwriteTruncate(sqlite3_file *pFile, sqlite_int64 size){
int rc;
static const char buf[50];
if( size ){
return SQLITE_IOERR;
}
rc = pFile->pMethods->xWrite(pFile, buf, sizeof(buf), 0);
if( rc==SQLITE_OK ){
rc = pFile->pMethods->xSync(pFile, SQLITE_SYNC_NORMAL);
}
return rc;
}
/*
** The delete method for journal files in the overwrite VFS.
*/
static int overwriteDelete(sqlite3_file *pFile){
return overwriteTruncate(pFile, 0);
}
/*
** The open method for overwrite VFS. If the file being opened is
** a journal file then substitute the alternative xTruncate method.
*/
static int overwriteOpen(
sqlite3_vfs *pVfs,
const char *zName,
sqlite3_file *pFile,
int flags,
int *pOutFlags
){
int rc;
sqlite3_vfs *pRealVfs;
int isJournal;
isJournal = (flags & (SQLITE_OPEN_MAIN_JOURNAL|SQLITE_OPEN_TEMP_JOURNAL))!=0;
pRealVfs = (sqlite3_vfs*)pVfs->pAppData;
rc = pRealVfs->xOpen(pRealVfs, zName, pFile, flags, pOutFlags);
if( rc==SQLITE_OK && isJournal ){
if( overwrite_methods.xTruncate==0 ){
sqlite3_io_methods temp;
memcpy(&temp, pFile->pMethods, sizeof(temp));
temp.xTruncate = overwriteTruncate;
memcpy(&overwrite_methods, &temp, sizeof(temp));
}
pFile->pMethods = &overwrite_methods;
}
return rc;
}
/*
** Overlay the overwrite VFS over top of the current default VFS
** and make the overlay VFS the new default.
**
** This routine can only be evaluated once. On second and subsequent
** executions it becomes a no-op.
*/
static void registerOverwriteVfs(void){
sqlite3_vfs *pBase;
if( overwrite_vfs.iVersion ) return;
pBase = sqlite3_vfs_find(0);
memcpy(&overwrite_vfs, pBase, sizeof(overwrite_vfs));
overwrite_vfs.pAppData = pBase;
overwrite_vfs.xOpen = overwriteOpen;
overwrite_vfs.zName = "overwriteVfs";
sqlite3_vfs_register(&overwrite_vfs, 1);
}
int main(int argc, char **argv){
sqlite3 *db;
int rc;
@@ -199,13 +116,6 @@ int main(int argc, char **argv){
while (argc>3)
{
if( argc>3 && strcmp(argv[1], "-overwrite")==0 ){
registerOverwriteVfs();
argv++;
argc--;
continue;
}
#ifdef HAVE_OSINST
if( argc>4 && (strcmp(argv[1], "-log")==0) ){
pVfs = sqlite3_instvfs_binarylog("oslog", 0, argv[2]);
@@ -264,7 +174,6 @@ int main(int argc, char **argv){
fprintf(stderr, "Usage: %s [options] FILENAME SQL-SCRIPT\n"
"Runs SQL-SCRIPT against a UTF8 database\n"
"\toptions:\n"
"\t-overwrite\n"
#ifdef HAVE_OSINST
"\t-log <log>\n"
#endif