Compare commits

...

5 Commits

Author SHA1 Message Date
dan 2626b22230 Store 64-bit offset values in osinst log files.
FossilOrigin-Name: 74d975c69abf1b8b8699e4f6539a4e411913196c90061e2c1246d25c16693ae0
2019-10-08 19:45:17 +00:00
dan de941c89af Avoid attempting to read 0 bytes from a file in the osinst vtab code.
FossilOrigin-Name: 1fb76c3e7d904cd2754270997d3d0c86237b0a630d6b1417578a8191e6e1687f
2019-10-07 10:29:18 +00:00
dan 665987c2b3 Fix a problem in Makefile.msc on this branch.
FossilOrigin-Name: ed3499a1a5c0f860b940af0edc6a6184d834001a68d59b36b0e1b21d2e6579ca
2019-10-05 19:37:04 +00:00
dan 2b9c55e379 Add a timestamp to each osinst log entry, to facilitate merging multiple log files.
FossilOrigin-Name: c9519c0cec3f0eae3ec4abe39fabbcc59a38d3c2eba11e19cfec4b769ed7376e
2019-10-05 19:17:40 +00:00
dan 68bddc6544 Have sqlite3.c automatically turn on osinst logging for all connections.
FossilOrigin-Name: eea231f81b3ca6196949a84e8e0eb73a1ed03cb1ddd21f3b24787999caef8b1a
2019-10-05 17:29:52 +00:00
10 changed files with 242 additions and 95 deletions
+5
View File
@@ -378,6 +378,8 @@ SRC += \
shell.c \
sqlite3.h
SRC += $(TOP)/src/test_osinst.c
# Source code to the test files.
#
TESTSRC = \
@@ -682,6 +684,9 @@ sessionfuzz$(TEXE): $(TOP)/test/sessionfuzz.c sqlite3.c sqlite3.h
dbfuzz$(TEXE): $(TOP)/test/dbfuzz.c sqlite3.c sqlite3.h
$(LTLINK) -o $@ $(DBFUZZ_OPT) $(TOP)/test/dbfuzz.c sqlite3.c $(TLIBS)
osinst2sql$(TEXE): $(TOP)/tool/osinst2sql.c sqlite3.c sqlite3.h
$(LTLINK) -o $@ $(TOP)/tool/osinst2sql.c sqlite3.c $(TLIBS)
DBFUZZ2_OPTS = \
-DSQLITE_THREADSAFE=0 \
-DSQLITE_OMIT_LOAD_EXTENSION \
+6 -2
View File
@@ -1346,7 +1346,8 @@ SRC01 = \
$(TOP)\src\where.c \
$(TOP)\src\wherecode.c \
$(TOP)\src\whereexpr.c \
$(TOP)\src\window.c
$(TOP)\src\window.c \
$(TOP)\src\test_osinst.c
# Core miscellaneous files.
#
@@ -1470,7 +1471,7 @@ SRC12 =
# All source code files.
#
SRC = $(SRC00) $(SRC01) $(SRC03) $(SRC04) $(SRC05) $(SRC06) $(SRC07) $(SRC08) $(SRC09) $(SRC10) $(SRC11)
SRC = $(SRC00) $(SRC01) $(SRC03) $(SRC04) $(SRC05) $(SRC06) $(SRC07) $(SRC08) $(SRC09) $(SRC10) $(SRC11)
# Source code to the test files.
#
@@ -1772,6 +1773,9 @@ fuzzershell.exe: $(TOP)\tool\fuzzershell.c $(SQLITE3C) $(SQLITE3H)
dbfuzz.exe: $(TOP)\test\dbfuzz.c $(SQLITE3C) $(SQLITE3H)
$(LTLINK) $(NO_WARN) $(DBFUZZ_COMPILE_OPTS) $(TOP)\test\dbfuzz.c $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS)
osinst2sql.exe: $(TOP)\tool\osinst2sql.c $(SQLITE3C) $(SQLITE3H)
$(LTLINK) $(NO_WARN) $(TOP)\tool\osinst2sql.c $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS)
fuzzcheck.exe: $(FUZZCHECK_SRC) $(SQLITE3C) $(SQLITE3H)
$(LTLINK) $(NO_WARN) $(FUZZCHECK_OPTS) $(FUZZCHECK_SRC) $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS)
+7
View File
@@ -297,6 +297,8 @@ SRC += \
shell.c \
sqlite3.h
SRC += $(TOP)/src/test_osinst.c
# Source code to the test files.
#
@@ -580,6 +582,11 @@ dbfuzz$(EXE): $(TOP)/test/dbfuzz.c sqlite3.c sqlite3.h
$(DBFUZZ_OPT) $(TOP)/test/dbfuzz.c sqlite3.c \
$(TLIBS) $(THREADLIB)
osinst2sql$(EXE): $(TOP)/tool/osinst2sql.c sqlite3.c sqlite3.h
$(TCCX) -o osinst2sql$(EXE) -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION \
$(DBFUZZ_OPT) $(TOP)/tool/osinst2sql.c sqlite3.c \
$(TLIBS) $(THREADLIB)
DBFUZZ2_OPTS = \
-DSQLITE_THREADSAFE=0 \
-DSQLITE_OMIT_LOAD_EXTENSION \
+14 -16
View File
@@ -1,11 +1,11 @@
C Version\s3.30.0
D 2019-10-04T15:03:17.190
C Store\s64-bit\soffset\svalues\sin\sosinst\slog\sfiles.
D 2019-10-08T19:45:17.191
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
F Makefile.in 578f123620087ea459aa08fa872810a25ca7c0aaf16331de985bfcddb5f1e747
F Makefile.in ee84c65aad5a4aa6f5f3a8e0b3f1d0becc326c2e8abff7d486e4effe69108918
F Makefile.linux-gcc f609543700659711fbd230eced1f01353117621dccae7b9fb70daa64236c5241
F Makefile.msc a463dca3c50d8a36094fe5c8c39077907f530b54edfc5388c66c85e2cfc8dc04
F Makefile.msc 60547a4355cfde4ead5a35021cb9353a94d7ec34cdd21c153b7f18b55db54159
F README.md 1514a365ffca3c138e00c5cc839906108a01011a6b082bad19b09781e3aa498a
F VERSION 4c516d84c2a5f26c477ed34c09ac4136630f71c68139631f2eb591b22eea7cf1
F aclocal.m4 a5c22d164aff7ed549d53a90fa56d56955281f50
@@ -447,7 +447,7 @@ F ext/userauth/userauth.c f81aa5a3ecacf406f170c62a144405858f6f6de51dbdc0920134e6
F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 x
F ltmain.sh 3ff0879076df340d2e23ae905484d8c15d5fdea8
F magic.txt 8273bf49ba3b0c8559cb2774495390c31fd61c60
F main.mk 09716d345766a55b25ed157b14786526cf67c761c61d99c53e117196fb3b391a
F main.mk f25161a34666c0087e1eda65a70189c0a0ed646d8bb345c5994d7111e60fa759
F mkso.sh fd21c06b063bb16a5d25deea1752c2da6ac3ed83
F mptest/config01.test 3c6adcbc50b991866855f1977ff172eb6d901271
F mptest/config02.test 4415dfe36c48785f751e16e32c20b077c28ae504
@@ -489,7 +489,7 @@ F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71
F src/insert.c 40557ebd69f4115e7a273f9304a8ab637a47ce44f3c6923396928f023967b5e8
F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa
F src/loadext.c 4ddc65ae13c0d93db0ceedc8b14a28c8c260513448b0eb8c5a2ac375e3b6a85d
F src/main.c 3851950717170ade4f6d718c18c6c7400ef5994c2a654679af2cff2ffd0fb2b9
F src/main.c 781a8a729a996af11636eef1972b2decfb5cea3bf982d86274d6e2e22db93788
F src/malloc.c 0f9da2a66b230a5785af94b9672126845099b57b70a32c987d04ac28c69da990
F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645
F src/mem1.c c12a42539b1ba105e3707d0e628ad70e611040d8f5e38cf942cee30c867083de
@@ -530,7 +530,7 @@ F src/shell.c.in d70bcf630c4073eaa994fa74be98886c781918e794cb8b562be8df10f018e27
F src/sqlite.h.in 5725a6b20190a1e8d662077a1c1c8ea889ad7be90dd803f914c2de226f5fe6ab
F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
F src/sqlite3ext.h cef696ce3293242c67b2339763608427bf72ee66f1f3a05389ac2a7b46001c31
F src/sqliteInt.h 246740eab76d3ac87f856f8d979567089e8749104c12932143a6ba570e38e415
F src/sqliteInt.h b3212ce855a590787bc091721a2e65148947f83e1faaa0394eaa3217ef44b048
F src/sqliteLimit.h 1513bfb7b20378aa0041e7022d04acb73525de35b80b252f1b83fedb4de6a76b
F src/status.c 46e7aec11f79dad50965a5ca5fa9de009f7d6bde08be2156f1538a0a296d4d0e
F src/table.c b46ad567748f24a326d9de40e5b9659f96ffff34
@@ -568,7 +568,7 @@ F src/test_multiplex.c e054459f7633f3ff8ce1245da724f9a8be189e4e
F src/test_multiplex.h 5436d03f2d0501d04f3ed50a75819e190495b635
F src/test_mutex.c 7f4337ba23ee6b1d2ec81c189653608cb069926a
F src/test_onefile.c f31e52e891c5fef6709b9fcef54ce660648a34172423a9cbdf4cbce3ba0049f4
F src/test_osinst.c 98ef31ff03d55497829ca0f6c74a9f4e1aa48690
F src/test_osinst.c 0a58f8a4b03274c84c97a1060dd702004f8f2f6d9af2dba9b4daa93786bf697a
F src/test_pcache.c a5cd24730cb43c5b18629043314548c9169abb00
F src/test_quota.c 6cb9297115b551f433a9ad1741817a9831abed99
F src/test_quota.h 2a8ad1952d1d2ca9af0ce0465e56e6c023b5e15d
@@ -1784,13 +1784,14 @@ F tool/mkshellc.tcl 70a9978e363b0f3280ca9ce1c46d72563ff479c1930a12a7375e3881b732
F tool/mksourceid.c d458f9004c837bee87a6382228ac20d3eae3c49ea3b0a5aace936f8b60748d3b
F tool/mkspeedsql.tcl a1a334d288f7adfe6e996f2e712becf076745c97
F tool/mksqlite3c-noext.tcl 4f7cfef5152b0c91920355cbfc1d608a4ad242cb819f1aea07f6d0274f584a7f
F tool/mksqlite3c.tcl 5fed3d75069d8f66f202d3b5200b0cea4aa7108481acd06732a06fdd42eb83a2
F tool/mksqlite3c.tcl 8c399f889354be656895d0d503cd9434cc222d67919265d87a0779122674e4d5
F tool/mksqlite3h.tcl 080873e3856eceb9d289a08a00c4b30f875ea3feadcbece796bd509b1532792c
F tool/mksqlite3internalh.tcl eb994013e833359137eb53a55acdad0b5ae1049b
F tool/mkvsix.tcl b9e0777a213c23156b6542842c238479e496ebf5
F tool/offsets.c fe4262fdfa378e8f5499a42136d17bf3b98f6091
F tool/omittest.tcl 27f9413c3343bac200a28d81e8234adb0f5e141c4771893cb19b40235a91f1e0
F tool/opcodesum.tcl 740ed206ba8c5040018988129abbf3089a0ccf4a
F tool/osinst2sql.c 112ed2fb0175d1a341b87557c2f4dbc40f1d97d267533840124bec7df2dc72e2
F tool/pagesig.c ff0ca355fd3c2398e933da5e22439bbff89b803b
F tool/replace.tcl 60f91e8dd06ab81f74d213ecbd9c9945f32ac048
F tool/restore_jrnl.tcl 6957a34f8f1f0f8285e07536225ec3b292a9024a
@@ -1846,10 +1847,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 7f9a4b6015ac332a04d3e394a6b3210fc95253d8786a261178a5639cb8d9d987
R f116075cb1c47b7928f41444f3803579
T +bgcolor * #d0c0ff
T +sym-release *
T +sym-version-3.30.0 *
U drh
Z edadfb0c72633ac9bcd13396063b6815
P 1fb76c3e7d904cd2754270997d3d0c86237b0a630d6b1417578a8191e6e1687f
R 3cd7734ca3a0cffa4c22dd2b9933bced
U dan
Z 83be8f87e7b61aedcd3403b05fb69071
+1 -1
View File
@@ -1 +1 @@
c20a35336432025445f9f7e289d0cc3e4003fb17f45a4ce74c6269c407c6e09f
74d975c69abf1b8b8699e4f6539a4e411913196c90061e2c1246d25c16693ae0
+32
View File
@@ -1147,6 +1147,11 @@ static int sqlite3Close(sqlite3 *db, int forceZombie){
int sqlite3_close(sqlite3 *db){ return sqlite3Close(db,0); }
int sqlite3_close_v2(sqlite3 *db){ return sqlite3Close(db,1); }
#ifdef SQLITE_ENABLE_OSINST
int sqlite3_vfslog_new(const char*,const char*,const char*,sqlite3_vfs**);
int sqlite3_vfslog_finalize(const char*);
#endif
/*
** Close the mutex on database connection db.
@@ -1252,6 +1257,13 @@ void sqlite3LeaveMutexAndCloseZombie(sqlite3 *db){
db->magic = SQLITE_MAGIC_ERROR;
#ifdef SQLITE_ENABLE_OSINST
if( db->pOsinstVfs ){
sqlite3_vfslog_finalize(db->pOsinstVfs->zName);
db->pOsinstVfs = 0;
}
#endif
/* The temp-database schema is allocated differently from the other schema
** objects (using sqliteMalloc() directly, instead of sqlite3BtreeSchema()).
** So it needs to be freed here. Todo: Why not roll the temp schema into
@@ -3187,6 +3199,25 @@ static int openDatabase(
}else{
rc = sqlite3ParseUri(zVfs, zFilename, &flags, &db->pVfs, &zOpen, &zErrMsg);
}
#ifdef SQLITE_ENABLE_OSINST
/* If this is not a temporary or ":memory:" database, create an osinst
** VFS to use. */
assert( db->pVfs );
if( rc==SQLITE_OK && zOpen && zOpen[0] && strcmp(":memory:", zOpen) ){
u32 iVal = 0;
char *zLog = 0;
sqlite3_randomness(sizeof(iVal), (void*)&iVal);
zLog = sqlite3_mprintf("%s-osinst-%08x", zOpen, iVal);
if( zLog==0 ){
rc = SQLITE_NOMEM_BKPT;
}else{
sqlite3_vfs *pVfs = 0;
rc = sqlite3_vfslog_new(zLog, db->pVfs->zName, zLog, &pVfs);
sqlite3_free(zLog);
db->pOsinstVfs = db->pVfs = pVfs;
}
}
#endif
if( rc!=SQLITE_OK ){
if( rc==SQLITE_NOMEM ) sqlite3OomFault(db);
sqlite3ErrorWithMsg(db, rc, zErrMsg ? "%s" : 0, zErrMsg);
@@ -3194,6 +3225,7 @@ static int openDatabase(
goto opendb_out;
}
/* Open the backend database driver */
rc = sqlite3BtreeOpen(db->pVfs, zOpen, db, &db->aDb[0].pBt, 0,
flags | SQLITE_OPEN_MAIN_DB);
+5
View File
@@ -15,6 +15,8 @@
#ifndef SQLITEINT_H
#define SQLITEINT_H
#define SQLITE_ENABLE_OSINST 1
/* Special Comments:
**
** Some comments have special meaning to the tools that measure test
@@ -1487,6 +1489,9 @@ struct sqlite3 {
#ifdef SQLITE_USER_AUTHENTICATION
sqlite3_userauth auth; /* User authentication information */
#endif
#ifdef SQLITE_ENABLE_OSINST
sqlite3_vfs *pOsinstVfs; /* osinst VFS to finalize, if any */
#endif
};
/*
+112 -76
View File
@@ -62,6 +62,7 @@
** CREATE TABLE v(
** event TEXT, // "xOpen", "xRead" etc.
** file TEXT, // Name of file this call applies to
** time INTEGER, // Timestamp
** clicks INTEGER, // Time spent in call
** rc INTEGER, // Return value
** size INTEGER, // Bytes read or written
@@ -247,14 +248,15 @@ static sqlite3_uint64 vfslog_time(){
}
#endif
static void vfslog_call(sqlite3_vfs *, int, int, sqlite3_int64, int, int, int);
static void vfslog_call(
sqlite3_vfs *, int, int, sqlite3_uint64, sqlite3_int64, int, int, sqlite_int64);
static void vfslog_string(sqlite3_vfs *, const char *);
/*
** Close an vfslog-file.
*/
static int vfslogClose(sqlite3_file *pFile){
sqlite3_uint64 t;
sqlite3_uint64 t, t2;
int rc = SQLITE_OK;
VfslogFile *p = (VfslogFile *)pFile;
@@ -262,8 +264,8 @@ static int vfslogClose(sqlite3_file *pFile){
if( p->pReal->pMethods ){
rc = p->pReal->pMethods->xClose(p->pReal);
}
t = vfslog_time() - t;
vfslog_call(p->pVfslog, OS_CLOSE, p->iFileId, t, rc, 0, 0);
t2 = vfslog_time() - t;
vfslog_call(p->pVfslog, OS_CLOSE, p->iFileId, t, t2, rc, 0, 0);
return rc;
}
@@ -277,12 +279,12 @@ static int vfslogRead(
sqlite_int64 iOfst
){
int rc;
sqlite3_uint64 t;
sqlite3_uint64 t, t2;
VfslogFile *p = (VfslogFile *)pFile;
t = vfslog_time();
rc = p->pReal->pMethods->xRead(p->pReal, zBuf, iAmt, iOfst);
t = vfslog_time() - t;
vfslog_call(p->pVfslog, OS_READ, p->iFileId, t, rc, iAmt, (int)iOfst);
t2 = vfslog_time() - t;
vfslog_call(p->pVfslog, OS_READ, p->iFileId, t, t2, rc, iAmt, iOfst);
return rc;
}
@@ -296,12 +298,12 @@ static int vfslogWrite(
sqlite_int64 iOfst
){
int rc;
sqlite3_uint64 t;
sqlite3_uint64 t, t2;
VfslogFile *p = (VfslogFile *)pFile;
t = vfslog_time();
rc = p->pReal->pMethods->xWrite(p->pReal, z, iAmt, iOfst);
t = vfslog_time() - t;
vfslog_call(p->pVfslog, OS_WRITE, p->iFileId, t, rc, iAmt, (int)iOfst);
t2 = vfslog_time() - t;
vfslog_call(p->pVfslog, OS_WRITE, p->iFileId, t, t2, rc, iAmt, iOfst);
return rc;
}
@@ -310,12 +312,12 @@ static int vfslogWrite(
*/
static int vfslogTruncate(sqlite3_file *pFile, sqlite_int64 size){
int rc;
sqlite3_uint64 t;
sqlite3_uint64 t, t2;
VfslogFile *p = (VfslogFile *)pFile;
t = vfslog_time();
rc = p->pReal->pMethods->xTruncate(p->pReal, size);
t = vfslog_time() - t;
vfslog_call(p->pVfslog, OS_TRUNCATE, p->iFileId, t, rc, 0, (int)size);
t2 = vfslog_time() - t;
vfslog_call(p->pVfslog, OS_TRUNCATE, p->iFileId, t, t2, rc, 0, size);
return rc;
}
@@ -324,12 +326,12 @@ static int vfslogTruncate(sqlite3_file *pFile, sqlite_int64 size){
*/
static int vfslogSync(sqlite3_file *pFile, int flags){
int rc;
sqlite3_uint64 t;
sqlite3_uint64 t, t2;
VfslogFile *p = (VfslogFile *)pFile;
t = vfslog_time();
rc = p->pReal->pMethods->xSync(p->pReal, flags);
t = vfslog_time() - t;
vfslog_call(p->pVfslog, OS_SYNC, p->iFileId, t, rc, flags, 0);
t2 = vfslog_time() - t;
vfslog_call(p->pVfslog, OS_SYNC, p->iFileId, t, t2, rc, flags, 0);
return rc;
}
@@ -338,12 +340,12 @@ static int vfslogSync(sqlite3_file *pFile, int flags){
*/
static int vfslogFileSize(sqlite3_file *pFile, sqlite_int64 *pSize){
int rc;
sqlite3_uint64 t;
sqlite3_uint64 t, t2;
VfslogFile *p = (VfslogFile *)pFile;
t = vfslog_time();
rc = p->pReal->pMethods->xFileSize(p->pReal, pSize);
t = vfslog_time() - t;
vfslog_call(p->pVfslog, OS_FILESIZE, p->iFileId, t, rc, 0, (int)*pSize);
t2 = vfslog_time() - t;
vfslog_call(p->pVfslog, OS_FILESIZE, p->iFileId, t, t2, rc, 0, *pSize);
return rc;
}
@@ -352,12 +354,12 @@ static int vfslogFileSize(sqlite3_file *pFile, sqlite_int64 *pSize){
*/
static int vfslogLock(sqlite3_file *pFile, int eLock){
int rc;
sqlite3_uint64 t;
sqlite3_uint64 t, t2;
VfslogFile *p = (VfslogFile *)pFile;
t = vfslog_time();
rc = p->pReal->pMethods->xLock(p->pReal, eLock);
t = vfslog_time() - t;
vfslog_call(p->pVfslog, OS_LOCK, p->iFileId, t, rc, eLock, 0);
t2 = vfslog_time() - t;
vfslog_call(p->pVfslog, OS_LOCK, p->iFileId, t, t2, rc, eLock, 0);
return rc;
}
@@ -366,12 +368,12 @@ static int vfslogLock(sqlite3_file *pFile, int eLock){
*/
static int vfslogUnlock(sqlite3_file *pFile, int eLock){
int rc;
sqlite3_uint64 t;
sqlite3_uint64 t, t2;
VfslogFile *p = (VfslogFile *)pFile;
t = vfslog_time();
rc = p->pReal->pMethods->xUnlock(p->pReal, eLock);
t = vfslog_time() - t;
vfslog_call(p->pVfslog, OS_UNLOCK, p->iFileId, t, rc, eLock, 0);
t2 = vfslog_time() - t;
vfslog_call(p->pVfslog, OS_UNLOCK, p->iFileId, t, t2, rc, eLock, 0);
return rc;
}
@@ -380,12 +382,12 @@ static int vfslogUnlock(sqlite3_file *pFile, int eLock){
*/
static int vfslogCheckReservedLock(sqlite3_file *pFile, int *pResOut){
int rc;
sqlite3_uint64 t;
sqlite3_uint64 t, t2;
VfslogFile *p = (VfslogFile *)pFile;
t = vfslog_time();
rc = p->pReal->pMethods->xCheckReservedLock(p->pReal, pResOut);
t = vfslog_time() - t;
vfslog_call(p->pVfslog, OS_CHECKRESERVEDLOCK, p->iFileId, t, rc, *pResOut, 0);
t2 = vfslog_time() - t;
vfslog_call(p->pVfslog, OS_CHECKRESERVEDLOCK, p->iFileId, t,t2,rc,*pResOut,0);
return rc;
}
@@ -406,12 +408,12 @@ static int vfslogFileControl(sqlite3_file *pFile, int op, void *pArg){
*/
static int vfslogSectorSize(sqlite3_file *pFile){
int rc;
sqlite3_uint64 t;
sqlite3_uint64 t, t2;
VfslogFile *p = (VfslogFile *)pFile;
t = vfslog_time();
rc = p->pReal->pMethods->xSectorSize(p->pReal);
t = vfslog_time() - t;
vfslog_call(p->pVfslog, OS_SECTORSIZE, p->iFileId, t, rc, 0, 0);
t2 = vfslog_time() - t;
vfslog_call(p->pVfslog, OS_SECTORSIZE, p->iFileId, t, t2, rc, 0, 0);
return rc;
}
@@ -420,23 +422,23 @@ static int vfslogSectorSize(sqlite3_file *pFile){
*/
static int vfslogDeviceCharacteristics(sqlite3_file *pFile){
int rc;
sqlite3_uint64 t;
sqlite3_uint64 t, t2;
VfslogFile *p = (VfslogFile *)pFile;
t = vfslog_time();
rc = p->pReal->pMethods->xDeviceCharacteristics(p->pReal);
t = vfslog_time() - t;
vfslog_call(p->pVfslog, OS_DEVCHAR, p->iFileId, t, rc, 0, 0);
t2 = vfslog_time() - t;
vfslog_call(p->pVfslog, OS_DEVCHAR, p->iFileId, t, t2, rc, 0, 0);
return rc;
}
static int vfslogShmLock(sqlite3_file *pFile, int ofst, int n, int flags){
int rc;
sqlite3_uint64 t;
sqlite3_uint64 t, t2;
VfslogFile *p = (VfslogFile *)pFile;
t = vfslog_time();
rc = p->pReal->pMethods->xShmLock(p->pReal, ofst, n, flags);
t = vfslog_time() - t;
vfslog_call(p->pVfslog, OS_SHMLOCK, p->iFileId, t, rc, 0, 0);
t2 = vfslog_time() - t;
vfslog_call(p->pVfslog, OS_SHMLOCK, p->iFileId, t, t2, rc, 0, 0);
return rc;
}
static int vfslogShmMap(
@@ -447,30 +449,30 @@ static int vfslogShmMap(
volatile void **pp
){
int rc;
sqlite3_uint64 t;
sqlite3_uint64 t, t2;
VfslogFile *p = (VfslogFile *)pFile;
t = vfslog_time();
rc = p->pReal->pMethods->xShmMap(p->pReal, iRegion, szRegion, isWrite, pp);
t = vfslog_time() - t;
vfslog_call(p->pVfslog, OS_SHMMAP, p->iFileId, t, rc, 0, 0);
t2 = vfslog_time() - t;
vfslog_call(p->pVfslog, OS_SHMMAP, p->iFileId, t, t2, rc, 0, 0);
return rc;
}
static void vfslogShmBarrier(sqlite3_file *pFile){
sqlite3_uint64 t;
sqlite3_uint64 t, t2;
VfslogFile *p = (VfslogFile *)pFile;
t = vfslog_time();
p->pReal->pMethods->xShmBarrier(p->pReal);
t = vfslog_time() - t;
vfslog_call(p->pVfslog, OS_SHMBARRIER, p->iFileId, t, SQLITE_OK, 0, 0);
t2 = vfslog_time() - t;
vfslog_call(p->pVfslog, OS_SHMBARRIER, p->iFileId, t, t2, SQLITE_OK, 0, 0);
}
static int vfslogShmUnmap(sqlite3_file *pFile, int deleteFlag){
int rc;
sqlite3_uint64 t;
sqlite3_uint64 t, t2;
VfslogFile *p = (VfslogFile *)pFile;
t = vfslog_time();
rc = p->pReal->pMethods->xShmUnmap(p->pReal, deleteFlag);
t = vfslog_time() - t;
vfslog_call(p->pVfslog, OS_SHMUNMAP, p->iFileId, t, rc, 0, 0);
t2 = vfslog_time() - t;
vfslog_call(p->pVfslog, OS_SHMUNMAP, p->iFileId, t, t2, rc, 0, 0);
return rc;
}
@@ -486,7 +488,7 @@ static int vfslogOpen(
int *pOutFlags
){
int rc;
sqlite3_uint64 t;
sqlite3_uint64 t, t2;
VfslogFile *p = (VfslogFile *)pFile;
VfslogVfs *pLog = (VfslogVfs *)pVfs;
@@ -497,9 +499,9 @@ static int vfslogOpen(
t = vfslog_time();
rc = REALVFS(pVfs)->xOpen(REALVFS(pVfs), zName, p->pReal, flags, pOutFlags);
t = vfslog_time() - t;
t2 = vfslog_time() - t;
vfslog_call(pVfs, OS_OPEN, p->iFileId, t, rc, 0, 0);
vfslog_call(pVfs, OS_OPEN, p->iFileId, t, t2, rc, 0, 0);
vfslog_string(pVfs, zName);
return rc;
}
@@ -511,11 +513,11 @@ static int vfslogOpen(
*/
static int vfslogDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){
int rc;
sqlite3_uint64 t;
sqlite3_uint64 t, t2;
t = vfslog_time();
rc = REALVFS(pVfs)->xDelete(REALVFS(pVfs), zPath, dirSync);
t = vfslog_time() - t;
vfslog_call(pVfs, OS_DELETE, 0, t, rc, dirSync, 0);
t2 = vfslog_time() - t;
vfslog_call(pVfs, OS_DELETE, 0, t, t2, rc, dirSync, 0);
vfslog_string(pVfs, zPath);
return rc;
}
@@ -531,11 +533,11 @@ static int vfslogAccess(
int *pResOut
){
int rc;
sqlite3_uint64 t;
sqlite3_uint64 t, t2;
t = vfslog_time();
rc = REALVFS(pVfs)->xAccess(REALVFS(pVfs), zPath, flags, pResOut);
t = vfslog_time() - t;
vfslog_call(pVfs, OS_ACCESS, 0, t, rc, flags, *pResOut);
t2 = vfslog_time() - t;
vfslog_call(pVfs, OS_ACCESS, 0, t, t2, rc, flags, (sqlite3_int64)*pResOut);
vfslog_string(pVfs, zPath);
return rc;
}
@@ -642,35 +644,45 @@ static void vfslog_flush(VfslogVfs *p){
#endif
}
static void put32bits(unsigned char *p, unsigned int v){
static void vfslogPut32bits(unsigned char *p, unsigned int v){
p[0] = v>>24;
p[1] = (unsigned char)(v>>16);
p[2] = (unsigned char)(v>>8);
p[3] = (unsigned char)v;
}
static void vfslogPut64bits(unsigned char *p, sqlite3_int64 v){
vfslogPut32bits(p, (v >> 32) & 0xFFFFFFFF);
vfslogPut32bits(&p[4], v & 0xFFFFFFFF);
}
#define VFSLOG_RECORD_SIZE 36
static void vfslog_call(
sqlite3_vfs *pVfs,
int eEvent,
int iFileid,
sqlite3_uint64 tStamp,
sqlite3_int64 nClick,
int return_code,
int size,
int offset
sqlite3_int64 offset
){
VfslogVfs *p = (VfslogVfs *)pVfs;
unsigned char *zRec;
if( (24+p->nBuf)>sizeof(p->aBuf) ){
if( (VFSLOG_RECORD_SIZE+p->nBuf)>sizeof(p->aBuf) ){
vfslog_flush(p);
}
zRec = (unsigned char *)&p->aBuf[p->nBuf];
put32bits(&zRec[0], eEvent);
put32bits(&zRec[4], iFileid);
put32bits(&zRec[8], (unsigned int)(nClick&0xffff));
put32bits(&zRec[12], return_code);
put32bits(&zRec[16], size);
put32bits(&zRec[20], offset);
p->nBuf += 24;
vfslogPut32bits(&zRec[0], eEvent);
vfslogPut32bits(&zRec[4], iFileid);
vfslogPut64bits(&zRec[8], (sqlite3_int64)tStamp);
vfslogPut32bits(&zRec[16], (unsigned int)(nClick&0xffffffff));
vfslogPut32bits(&zRec[20], return_code);
vfslogPut32bits(&zRec[24], size);
vfslogPut64bits(&zRec[28], offset);
p->nBuf += VFSLOG_RECORD_SIZE;
}
static void vfslog_string(sqlite3_vfs *pVfs, const char *zStr){
@@ -681,7 +693,7 @@ static void vfslog_string(sqlite3_vfs *pVfs, const char *zStr){
vfslog_flush(p);
}
zRec = (unsigned char *)&p->aBuf[p->nBuf];
put32bits(&zRec[0], nStr);
vfslogPut32bits(&zRec[0], nStr);
if( zStr ){
memcpy(&zRec[4], zStr, nStr);
}
@@ -710,7 +722,8 @@ int sqlite3_vfslog_finalize(const char *zVfs){
int sqlite3_vfslog_new(
const char *zVfs, /* New VFS name */
const char *zParentVfs, /* Parent VFS name (or NULL) */
const char *zLog /* Log file name */
const char *zLog, /* Log file name */
sqlite3_vfs **ppVfs /* OUT: New VFS object */
){
VfslogVfs *p;
sqlite3_vfs *pParent;
@@ -747,7 +760,8 @@ int sqlite3_vfslog_new(
memcpy(p->aBuf, "sqlite_ostrace1.....", 20);
p->iOffset = 0;
p->nBuf = 20;
rc = sqlite3_vfs_register((sqlite3_vfs *)p, 1);
rc = sqlite3_vfs_register((sqlite3_vfs *)p, 0);
if( ppVfs ) *ppVfs = (sqlite3_vfs*)p;
}
if( rc ){
vfslog_finalize(p);
@@ -757,11 +771,12 @@ int sqlite3_vfslog_new(
int sqlite3_vfslog_annotate(const char *zVfs, const char *zMsg){
sqlite3_vfs *pVfs;
sqlite3_uint64 t = vfslog_time();
pVfs = sqlite3_vfs_find(zVfs);
if( !pVfs || pVfs->xOpen!=vfslogOpen ){
return SQLITE_ERROR;
}
vfslog_call(pVfs, OS_ANNOTATE, 0, 0, 0, 0, 0);
vfslog_call(pVfs, OS_ANNOTATE, 0, t, 0, 0, 0, 0);
vfslog_string(pVfs, zMsg);
return SQLITE_OK;
}
@@ -899,7 +914,7 @@ static int vlogConnect(
if( rc==SQLITE_OK ){
p->pFd->pMethods->xFileSize(p->pFd, &p->nByte);
sqlite3_declare_vtab(db,
"CREATE TABLE xxx(event, file, click, rc, size, offset)"
"CREATE TABLE xxx(event, file, time, click, rc, size, offset)"
);
*ppVtab = &p->base;
}else{
@@ -971,7 +986,7 @@ static int vlogNext(sqlite3_vtab_cursor *pCursor){
sqlite3_free(pCsr->zTransient);
pCsr->zTransient = 0;
nRead = 24;
nRead = VFSLOG_RECORD_SIZE;
if( pCsr->iOffset+nRead<=p->nByte ){
int eEvent;
rc = p->pFd->pMethods->xRead(p->pFd, pCsr->aBuf, nRead, pCsr->iOffset);
@@ -986,7 +1001,9 @@ static int vlogNext(sqlite3_vtab_cursor *pCursor){
if( rc==SQLITE_OK ){
int nStr = get32bits((unsigned char *)buf);
char *zStr = sqlite3_malloc(nStr+1);
rc = p->pFd->pMethods->xRead(p->pFd, zStr, nStr, pCsr->iOffset+nRead);
if( nStr>0 ){
rc = p->pFd->pMethods->xRead(p->pFd, zStr, nStr, pCsr->iOffset+nRead);
}
zStr[nStr] = '\0';
nRead += nStr;
@@ -1035,18 +1052,18 @@ static int vlogColumn(
sqlite3_context *ctx,
int i
){
unsigned int val;
VfslogCsr *pCsr = (VfslogCsr *)pCursor;
assert( i<7 );
val = get32bits(&pCsr->aBuf[4*i]);
switch( i ){
case 0: {
unsigned int val = get32bits(&pCsr->aBuf[0]);
sqlite3_result_text(ctx, vfslog_eventname(val), -1, SQLITE_STATIC);
break;
}
case 1: {
unsigned int val = get32bits(&pCsr->aBuf[4]);
char *zStr = pCsr->zTransient;
if( val!=0 && val<(unsigned)pCsr->nFile ){
zStr = pCsr->azFile[val];
@@ -1054,9 +1071,27 @@ static int vlogColumn(
sqlite3_result_text(ctx, zStr, -1, SQLITE_TRANSIENT);
break;
}
default:
case 2: {
unsigned int v1 = get32bits(&pCsr->aBuf[8]);
unsigned int v2 = get32bits(&pCsr->aBuf[12]);
sqlite3_result_int64(
ctx,(((sqlite3_int64)v1) << 32) + (sqlite3_int64)v2
);
break;
}
case 6: {
unsigned int v1 = get32bits(&pCsr->aBuf[28]);
unsigned int v2 = get32bits(&pCsr->aBuf[32]);
sqlite3_result_int64(
ctx,(((sqlite3_int64)v1) << 32) + (sqlite3_int64)v2
);
break;
}
default: {
unsigned int val = get32bits(&pCsr->aBuf[4*(i+1)]);
sqlite3_result_int(ctx, val);
break;
}
}
return SQLITE_OK;
@@ -1180,11 +1215,12 @@ static int SQLITE_TCLAPI test_vfslog(
zParent = Tcl_GetString(objv[3]);
zLog = Tcl_GetString(objv[4]);
if( *zParent=='\0' ) zParent = 0;
rc = sqlite3_vfslog_new(zVfs, zParent, zLog);
rc = sqlite3_vfslog_new(zVfs, zParent, zLog, 0);
if( rc!=SQLITE_OK ){
Tcl_AppendResult(interp, "failed", 0);
return TCL_ERROR;
}
sqlite3_vfs_register(sqlite3_vfs_find(zVfs), 1);
break;
};
+2
View File
@@ -403,6 +403,8 @@ foreach file {
sqlite3session.c
fts5.c
stmt.c
test_osinst.c
} {
copy_file tsrc/$file
}
+58
View File
@@ -0,0 +1,58 @@
/*
******************************************************************************
*/
#include <sqlite3.h>
#include <assert.h>
#include <stdio.h>
int sqlite3_vfslog_register(sqlite3 *db);
static int xCallback(void *pUnused, int nArg, char **azArg, char **azName){
char *zPrint = 0;
assert( nArg==7 );
zPrint = sqlite3_mprintf(
"INSERT INTO osinst VALUES(%Q, %Q, %s, %s, %s, %s, %s);",
azArg[0], azArg[1], azArg[2], azArg[3], azArg[4], azArg[5], azArg[6]
);
printf("%s\n", zPrint);
sqlite3_free(zPrint);
return SQLITE_OK;
}
int main(int argc, char **argv){
sqlite3 *db = 0;
int i;
sqlite3_open("", &db);
sqlite3_vfslog_register(db);
printf("BEGIN;\n");
printf("CREATE TABLE IF NOT EXISTS osinst(\n");
printf(" event TEXT, -- xOpen, xRead etc.\n");
printf(" file TEXT, -- Name of file this call applies to\n");
printf(" time INTEGER, -- Timestamp\n");
printf(" clicks INTEGER, -- Time spent in call\n");
printf(" rc INTEGER, -- Return value\n");
printf(" size INTEGER, -- Bytes read or written\n");
printf(" offset INTEGER -- File offset read or written\n");
printf(");\n");
for(i=1; i<argc; i++){
char *zSql = 0;
sqlite3_exec(db, "DROP TABLE IF EXISTS osinst;", 0, 0, 0);
zSql = sqlite3_mprintf(
"CREATE VIRTUAL TABLE osinst USING vfslog(%Q)", argv[i]
);
sqlite3_exec(db, zSql, 0, 0, 0);
sqlite3_free(zSql);
sqlite3_exec(db, "SELECT * FROM osinst", xCallback, 0, 0);
}
printf("COMMIT;\n");
sqlite3_close(db);
return 0;
}