1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-12 13:01:09 +03:00

Consolidated inline assembly versions of "hwtime()" into hwtime.h. Provided MSVC version. Modified code for consistent use of hwtime(). Changed implementation to use sqlite_uint64 and sqlite_int64 instead of unsigned long long int and long long int for MSVC compiler support. (CVS 5178)

FossilOrigin-Name: 9883b406ce24eae93942ee5e6aab33fb6b05329f
This commit is contained in:
shane
2008-05-29 20:22:37 +00:00
parent 174edc6477
commit 9bcbdad298
15 changed files with 238 additions and 173 deletions

View File

@@ -194,6 +194,7 @@ SRC = \
$(TOP)/src/func.c \ $(TOP)/src/func.c \
$(TOP)/src/hash.c \ $(TOP)/src/hash.c \
$(TOP)/src/hash.h \ $(TOP)/src/hash.h \
$(TOP)/src/hwtime.h \
$(TOP)/src/insert.c \ $(TOP)/src/insert.c \
$(TOP)/src/journal.c \ $(TOP)/src/journal.c \
$(TOP)/src/legacy.c \ $(TOP)/src/legacy.c \
@@ -362,6 +363,7 @@ HDR = \
$(TOP)/src/btree.h \ $(TOP)/src/btree.h \
$(TOP)/src/btreeInt.h \ $(TOP)/src/btreeInt.h \
$(TOP)/src/hash.h \ $(TOP)/src/hash.h \
$(TOP)/src/hwtime.h \
$(TOP)/src/sqliteLimit.h \ $(TOP)/src/sqliteLimit.h \
$(TOP)/src/mutex.h \ $(TOP)/src/mutex.h \
opcodes.h \ opcodes.h \

View File

@@ -101,6 +101,7 @@ SRC = \
$(TOP)/src/func.c \ $(TOP)/src/func.c \
$(TOP)/src/hash.c \ $(TOP)/src/hash.c \
$(TOP)/src/hash.h \ $(TOP)/src/hash.h \
$(TOP)/src/hwtime.h \
$(TOP)/src/insert.c \ $(TOP)/src/insert.c \
$(TOP)/src/journal.c \ $(TOP)/src/journal.c \
$(TOP)/src/legacy.c \ $(TOP)/src/legacy.c \
@@ -250,6 +251,7 @@ HDR = \
$(TOP)/src/btree.h \ $(TOP)/src/btree.h \
$(TOP)/src/btreeInt.h \ $(TOP)/src/btreeInt.h \
$(TOP)/src/hash.h \ $(TOP)/src/hash.h \
$(TOP)/src/hwtime.h \
keywordhash.h \ keywordhash.h \
$(TOP)/src/mutex.h \ $(TOP)/src/mutex.h \
opcodes.h \ opcodes.h \

View File

@@ -1,7 +1,7 @@
C Fix\scosmetic\sissues\sspotted\swhile\sworking\son\sticket\s#3146\s(CVS\s5177) C Consolidated\sinline\sassembly\sversions\sof\s"hwtime()"\sinto\shwtime.h.\s\sProvided\sMSVC\sversion.\s\sModified\scode\sfor\sconsistent\suse\sof\shwtime().\s\sChanged\simplementation\sto\suse\ssqlite_uint64\sand\ssqlite_int64\sinstead\sof\sunsigned\slong\slong\sint\sand\slong\slong\sint\sfor\sMSVC\scompiler\ssupport.\s(CVS\s5178)
D 2008-05-29T05:23:42 D 2008-05-29T20:22:37
F Makefile.arm-wince-mingw32ce-gcc ac5f7b2cef0cd850d6f755ba6ee4ab961b1fadf7 F Makefile.arm-wince-mingw32ce-gcc ac5f7b2cef0cd850d6f755ba6ee4ab961b1fadf7
F Makefile.in 62b2a40ff5944dd33c9c3184b21f720ea8e48a44 F Makefile.in ce92ea8dc7adfb743757794f51c10d1b0d9c55e4
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
F README b974cdc3f9f12b87e851b04e75996d720ebf81ac F README b974cdc3f9f12b87e851b04e75996d720ebf81ac
F VERSION 0993b4f2f08c496fab78af42928b6dc745f8a2e1 F VERSION 0993b4f2f08c496fab78af42928b6dc745f8a2e1
@@ -76,7 +76,7 @@ F ext/rtree/rtree_util.tcl ee0a0311eb12175319d78bfb37302320496cee6e
F ext/rtree/viewrtree.tcl 09526398dae87a5a87c5aac2b3854dbaf8376869 F ext/rtree/viewrtree.tcl 09526398dae87a5a87c5aac2b3854dbaf8376869
F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895
F ltmain.sh 09fe5815427dc7d0abb188bbcdf0e34896577210 F ltmain.sh 09fe5815427dc7d0abb188bbcdf0e34896577210
F main.mk 0fdc9417630e829cae994efee59038810f091e33 F main.mk 254bdf904af5869178e6b333be5729bf24ff3f77
F mkdll.sh 712e74f3efe08a6ba12b2945d018a29a89d7fe3b F mkdll.sh 712e74f3efe08a6ba12b2945d018a29a89d7fe3b
F mkextu.sh 416f9b7089d80e5590a29692c9d9280a10dbad9f F mkextu.sh 416f9b7089d80e5590a29692c9d9280a10dbad9f
F mkextw.sh 1a866b53637dab137191341cc875575a5ca110fb F mkextw.sh 1a866b53637dab137191341cc875575a5ca110fb
@@ -109,6 +109,7 @@ F src/fault.c 1f6177188edb00641673e462f3fab8cba9f7422b
F src/func.c 77a910a1ca7613d291fd0b5cba3be14c02f0dce0 F src/func.c 77a910a1ca7613d291fd0b5cba3be14c02f0dce0
F src/hash.c fd8cb06fb54c2fe7d48c9195792059a2e5be8b70 F src/hash.c fd8cb06fb54c2fe7d48c9195792059a2e5be8b70
F src/hash.h 031cd9f915aff27e12262cb9eb570ac1b8326b53 F src/hash.h 031cd9f915aff27e12262cb9eb570ac1b8326b53
F src/hwtime.h 10fae2093aefa2b00be13bcac40c06e90924bc83
F src/insert.c e3277f313352ac27282b5be39972fda4f315d0c6 F src/insert.c e3277f313352ac27282b5be39972fda4f315d0c6
F src/journal.c cffd2cd214e58c0e99c3ff632b3bee6c7cbb260e F src/journal.c cffd2cd214e58c0e99c3ff632b3bee6c7cbb260e
F src/legacy.c 8f5a2b25d9673b4004287cf2bf51dbf7d0738406 F src/legacy.c 8f5a2b25d9673b4004287cf2bf51dbf7d0738406
@@ -128,9 +129,9 @@ F src/mutex_unix.c 466d20378a0645fea64c3f2e2669c33b7802df56
F src/mutex_w32.c 133698096a2c4e81cd11ea6f4de7891c66f7b9f7 F src/mutex_w32.c 133698096a2c4e81cd11ea6f4de7891c66f7b9f7
F src/os.c 541ea39fbacc18483b3aa96cd0242bad2dd0f049 F src/os.c 541ea39fbacc18483b3aa96cd0242bad2dd0f049
F src/os.h 6e7e5d4efdc907b7a1a8cddb0cf984af01843fad F src/os.h 6e7e5d4efdc907b7a1a8cddb0cf984af01843fad
F src/os_common.h 9da7339466404707af49943fe4c47e608034761b F src/os_common.h 24525d8b7bce66c374dfc1810a6c9043f3359b60
F src/os_os2.c 1578149e21c4eac42c7f230a6f40500846f8e781 F src/os_os2.c 1578149e21c4eac42c7f230a6f40500846f8e781
F src/os_unix.c 06dceb3230249d6e7c6a1d8d602fa6a93f4085b9 F src/os_unix.c a6b02934fdd4682db47c006cb03baac8694d8b77
F src/os_win.c 812f9ba8cd90c8aa54914a56897fb534494576d8 F src/os_win.c 812f9ba8cd90c8aa54914a56897fb534494576d8
F src/pager.c d0a77feeaeecaaaec9342a3bb3865ed9a490897a F src/pager.c d0a77feeaeecaaaec9342a3bb3865ed9a490897a
F src/pager.h 1ccde54041195311c2b09b6936404d2192db44da F src/pager.h 1ccde54041195311c2b09b6936404d2192db44da
@@ -167,7 +168,7 @@ F src/test_loadext.c 22065d601a18878e5542191001f0eaa5d77c0ed8
F src/test_malloc.c 5c2c698355613d321f216ece25901be1040cc1fb F src/test_malloc.c 5c2c698355613d321f216ece25901be1040cc1fb
F src/test_md5.c 28209a4e2068711b5443c33104fe41f21d160071 F src/test_md5.c 28209a4e2068711b5443c33104fe41f21d160071
F src/test_onefile.c fd994d397b0e9cad103b1a6e1f76c61a90a38752 F src/test_onefile.c fd994d397b0e9cad103b1a6e1f76c61a90a38752
F src/test_osinst.c c684ee6d480f30e36cb564dcbc94f5f8467468a8 F src/test_osinst.c acf306ba86a2963ba69dd87907fae447478a28f1
F src/test_schema.c e3f93725f7c5b2cff84a69dc4332040dfbc8f81a F src/test_schema.c e3f93725f7c5b2cff84a69dc4332040dfbc8f81a
F src/test_server.c 7e579eb9bf6fbe9cc45e84e4c74d3d06d049a825 F src/test_server.c 7e579eb9bf6fbe9cc45e84e4c74d3d06d049a825
F src/test_tclvar.c e99b975614735553fa1c43503d85b0dd988c0e77 F src/test_tclvar.c e99b975614735553fa1c43503d85b0dd988c0e77
@@ -178,8 +179,8 @@ F src/update.c 2d7143b9014e955509cc4f323f9a9584fb898f34
F src/utf.c 8c94fa10efc78c2568d08d436acc59df4df7191b F src/utf.c 8c94fa10efc78c2568d08d436acc59df4df7191b
F src/util.c 43277088f8fea4109a640aa46731b8752c3fb4a7 F src/util.c 43277088f8fea4109a640aa46731b8752c3fb4a7
F src/vacuum.c a5c289e561ed72283e97d2485491986bc7d684eb F src/vacuum.c a5c289e561ed72283e97d2485491986bc7d684eb
F src/vdbe.c efe92d0925bc0a6f76c5bbfaf4cfee1665ae8799 F src/vdbe.c 37d3237ad5b84c4d4d3a33a49350c2594cac65c3
F src/vdbe.h f4bb70962d9c13e0f65b215c90e8acea1ae6e8ee F src/vdbe.h 1e3722d471739c2b213c6283b60373290e52f7ea
F src/vdbeInt.h ede1a31cfa74d4718f41da491bd1d2b3abc137fc F src/vdbeInt.h ede1a31cfa74d4718f41da491bd1d2b3abc137fc
F src/vdbeapi.c 22b01ed175e4d4c613ee82cabc7a44a275641206 F src/vdbeapi.c 22b01ed175e4d4c613ee82cabc7a44a275641206
F src/vdbeaux.c 7823f1db7f47cf70d86d1901e2030309e1cbfd02 F src/vdbeaux.c 7823f1db7f47cf70d86d1901e2030309e1cbfd02
@@ -575,8 +576,8 @@ F tool/memleak2.awk 9cc20c8e8f3c675efac71ea0721ee6874a1566e8
F tool/memleak3.tcl 7707006ee908cffff210c98158788d85bb3fcdbf F tool/memleak3.tcl 7707006ee908cffff210c98158788d85bb3fcdbf
F tool/mkkeywordhash.c ef93810fc41fb3d3dbacf9a33a29be88ea99ffa9 F tool/mkkeywordhash.c ef93810fc41fb3d3dbacf9a33a29be88ea99ffa9
F tool/mkopts.tcl 66ac10d240cc6e86abd37dc908d50382f84ff46e x F tool/mkopts.tcl 66ac10d240cc6e86abd37dc908d50382f84ff46e x
F tool/mksqlite3c.tcl da45d6d596f536d361e428874e7071710803de1e F tool/mksqlite3c.tcl 927b9d6ccd05690f75eb67bce7cca9a90b65ceeb
F tool/mksqlite3internalh.tcl 47737a925fb02fce43e2c0a14b3cc17574a4d44a F tool/mksqlite3internalh.tcl 7b43894e21bcb1bb39e11547ce7e38a063357e87
F tool/omittest.tcl 7d1fdf469e2f4d175f70c36e469db64a1626fabb F tool/omittest.tcl 7d1fdf469e2f4d175f70c36e469db64a1626fabb
F tool/opcodeDoc.awk b3a2a3d5d3075b8bd90b7afe24283efdd586659c F tool/opcodeDoc.awk b3a2a3d5d3075b8bd90b7afe24283efdd586659c
F tool/report1.txt 9eae07f26a8fc53889b45fc833a66a33daa22816 F tool/report1.txt 9eae07f26a8fc53889b45fc833a66a33daa22816
@@ -586,11 +587,11 @@ F tool/soak1.tcl 85a4a7826c77351bfe1c005ae3cff2ef59123557
F tool/space_used.tcl f714c41a59e326b8b9042f415b628b561bafa06b F tool/space_used.tcl f714c41a59e326b8b9042f415b628b561bafa06b
F tool/spaceanal.tcl b87db46ae29e3116411b1686e136b9b994d7de39 F tool/spaceanal.tcl b87db46ae29e3116411b1686e136b9b994d7de39
F tool/speedtest.tcl 06c76698485ccf597b9e7dbb1ac70706eb873355 F tool/speedtest.tcl 06c76698485ccf597b9e7dbb1ac70706eb873355
F tool/speedtest16.c 6f5bc019dcf8b6537f379bbac0408a9e1a86f0b6 F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81
F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
F tool/speedtest8.c e74126bc12178fa29904f711bb100212a5448041 F tool/speedtest8.c 1dbced29de5f59ba2ebf877edcadf171540374d1
F tool/speedtest8inst1.c 025879132979a5fdec11218472cba6cf8f6ec854 F tool/speedtest8inst1.c c65494ca99d1e09c246dfe37a7ca7a354af9990f
P ad6a782e7c408f6c3ebff5f2715c629b75c8002d P 5f6eab65dba421a736659a6673a51a0e487d68ac
R 486eefc4a3f966d0ff0a629a9a11c14c R 458af2184cd56db6e376c81a0c3c302b
U drh U shane
Z 38197e0cbfc994144353080aecc69a7d Z a36aff0535891ea4228fb00ae4809b6b

View File

@@ -1 +1 @@
5f6eab65dba421a736659a6673a51a0e487d68ac 9883b406ce24eae93942ee5e6aab33fb6b05329f

65
src/hwtime.h Normal file
View File

@@ -0,0 +1,65 @@
/*
** 2008 May 27
**
** 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 contains inline asm code for retrieving "high-performance"
** counters for x86 class CPUs.
**
** $Id: hwtime.h,v 1.1 2008/05/29 20:22:37 shane Exp $
*/
#ifndef _HWTIME_H_
#define _HWTIME_H_
/*
** The following routine only works on pentium-class (or newer) processors.
** It uses the RDTSC opcode to read the cycle count value out of the
** processor and returns that value. This can be used for high-res
** profiling.
*/
#if (defined(__GNUC__) || defined(_MSC_VER)) && \
(defined(i386) || defined(__i386__) || defined(_M_IX86))
#if defined(__GNUC__)
__inline__ sqlite_uint64 sqlite3Hwtime(void){
unsigned int lo, hi;
/* We cannot use "=A", since this would use %rax on x86_64 */
__asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi));
return (sqlite_uint64)hi << 32 | lo;
}
#elif defined(_MSC_VER)
__declspec(naked) __inline sqlite_uint64 __cdecl sqlite3Hwtime(void){
__asm {
rdtsc
ret ; return value at EDX:EAX
}
}
#endif
#else
#error Need implementation of sqlite3Hwtime() for your platform.
/*
** To compile without implementing sqlite3Hwtime() for your platform,
** you can remove the above #error and use the following
** stub function. You will lose timing support for many
** of the debugging and testing utilities, but it should at
** least compile and run.
*/
sqlite_uint64 sqlite3Hwtime(void){ return ((sqlite_uint64)0); }
#endif
#endif /* !defined(_HWTIME_H_) */

View File

@@ -17,8 +17,10 @@
** This file should be #included by the os_*.c files only. It is not a ** This file should be #included by the os_*.c files only. It is not a
** general purpose header file. ** general purpose header file.
** **
** $Id: os_common.h,v 1.36 2008/05/16 04:51:55 danielk1977 Exp $ ** $Id: os_common.h,v 1.37 2008/05/29 20:22:37 shane Exp $
*/ */
#ifndef _OS_COMMON_H_
#define _OS_COMMON_H_
/* /*
** At least two bugs have slipped in because we changed the MEMORY_DEBUG ** At least two bugs have slipped in because we changed the MEMORY_DEBUG
@@ -64,22 +66,22 @@ int sqlite3OSTrace = 0;
** on i486 hardware. ** on i486 hardware.
*/ */
#ifdef SQLITE_PERFORMANCE_TRACE #ifdef SQLITE_PERFORMANCE_TRACE
__inline__ unsigned long long int hwtime(void){
unsigned long long int x; /*
__asm__("rdtsc\n\t" ** hwtime.h contains inline assembler code for implementing
"mov %%edx, %%ecx\n\t" ** high-performance timing routines.
:"=A" (x)); */
return x; #include "hwtime.h"
}
static unsigned long long int g_start; static sqlite_uint64 g_start;
static unsigned int elapse; static sqlite_uint64 g_elapsed;
#define TIMER_START g_start=hwtime() #define TIMER_START g_start=sqlite3Hwtime()
#define TIMER_END elapse=hwtime()-g_start #define TIMER_END g_elapsed=sqlite3Hwtime()-g_start
#define TIMER_ELAPSED elapse #define TIMER_ELAPSED g_elapsed
#else #else
#define TIMER_START #define TIMER_START
#define TIMER_END #define TIMER_END
#define TIMER_ELAPSED 0 #define TIMER_ELAPSED ((sqlite_uint64)0)
#endif #endif
/* /*
@@ -131,3 +133,5 @@ int sqlite3_open_file_count = 0;
#else #else
#define OpenCounter(X) #define OpenCounter(X)
#endif #endif
#endif /* !defined(_OS_COMMON_H_) */

View File

@@ -12,7 +12,7 @@
** **
** This file contains code that is specific to Unix systems. ** This file contains code that is specific to Unix systems.
** **
** $Id: os_unix.c,v 1.182 2008/05/16 04:51:55 danielk1977 Exp $ ** $Id: os_unix.c,v 1.183 2008/05/29 20:22:37 shane Exp $
*/ */
#include "sqliteInt.h" #include "sqliteInt.h"
#if OS_UNIX /* This file is used on unix only */ #if OS_UNIX /* This file is used on unix only */
@@ -805,7 +805,7 @@ static int seekAndRead(unixFile *id, sqlite3_int64 offset, void *pBuf, int cnt){
got = read(id->h, pBuf, cnt); got = read(id->h, pBuf, cnt);
#endif #endif
TIMER_END; TIMER_END;
OSTRACE5("READ %-3d %5d %7lld %d\n", id->h, got, offset, TIMER_ELAPSED); OSTRACE5("READ %-3d %5d %7lld %llu\n", id->h, got, offset, TIMER_ELAPSED);
return got; return got;
} }
@@ -853,7 +853,7 @@ static int seekAndWrite(unixFile *id, i64 offset, const void *pBuf, int cnt){
got = write(id->h, pBuf, cnt); got = write(id->h, pBuf, cnt);
#endif #endif
TIMER_END; TIMER_END;
OSTRACE5("WRITE %-3d %5d %7lld %d\n", id->h, got, offset, TIMER_ELAPSED); OSTRACE5("WRITE %-3d %5d %7lld %llu\n", id->h, got, offset, TIMER_ELAPSED);
return got; return got;
} }

View File

@@ -14,7 +14,7 @@
** adds instrumentation to all vfs and file methods. C and Tcl interfaces ** adds instrumentation to all vfs and file methods. C and Tcl interfaces
** are provided to control the instrumentation. ** are provided to control the instrumentation.
** **
** $Id: test_osinst.c,v 1.11 2008/05/16 04:51:55 danielk1977 Exp $ ** $Id: test_osinst.c,v 1.12 2008/05/29 20:22:37 shane Exp $
*/ */
/* /*
@@ -53,8 +53,8 @@
** **
** * The name of the invoked method - i.e. "xRead". ** * The name of the invoked method - i.e. "xRead".
** **
** * The time consumed by the method call as measured by hwtime() (an ** * The time consumed by the method call as measured by
** integer value) ** sqlite3Hwtime() (an integer value)
** **
** * A string value with a different meaning for different calls. ** * A string value with a different meaning for different calls.
** For file methods, the name of the file being operated on. For ** For file methods, the name of the file being operated on. For
@@ -82,7 +82,7 @@
** * The name of the method call - i.e. "xWrite", ** * The name of the method call - i.e. "xWrite",
** * The total number of calls to the method (an integer). ** * The total number of calls to the method (an integer).
** * The aggregate time consumed by all calls to the method as ** * The aggregate time consumed by all calls to the method as
** measured by hwtime() (an integer). ** measured by sqlite3Hwtime() (an integer).
*/ */
#include "sqlite3.h" #include "sqlite3.h"
@@ -222,30 +222,19 @@ static sqlite3_io_methods inst_io_methods = {
instDeviceCharacteristics /* xDeviceCharacteristics */ instDeviceCharacteristics /* xDeviceCharacteristics */
}; };
/* /*
** The following routine only works on pentium-class processors. ** hwtime.h contains inline assembler code for implementing
** It uses the RDTSC opcode to read the cycle count value out of the ** high-performance timing routines.
** processor and returns that value. This can be used for high-res
** profiling.
*/ */
#if defined(i386) || defined(__i386__) || defined(_M_IX86) #include "hwtime.h"
__inline__ unsigned long long int osinst_hwtime(void){
unsigned int lo, hi;
/* We cannot use "=A", since this would use %rax on x86_64 */
__asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi));
return (unsigned long long int)hi << 32 | lo;
}
#else
static unsigned long long int osinst_hwtime(void){ return 0; }
#endif
#define OS_TIME_IO(eEvent, A, B, Call) { \ #define OS_TIME_IO(eEvent, A, B, Call) { \
inst_file *p = (inst_file *)pFile; \ inst_file *p = (inst_file *)pFile; \
InstVfs *pInstVfs = p->pInstVfs; \ InstVfs *pInstVfs = p->pInstVfs; \
int rc; \ int rc; \
sqlite3_int64 t = osinst_hwtime(); \ sqlite_uint64 t = sqlite3Hwtime(); \
rc = Call; \ rc = Call; \
t = osinst_hwtime() - t; \ t = sqlite3Hwtime() - t; \
pInstVfs->aTime[eEvent] += t; \ pInstVfs->aTime[eEvent] += t; \
pInstVfs->aCount[eEvent] += 1; \ pInstVfs->aCount[eEvent] += 1; \
if( pInstVfs->xCall ){ \ if( pInstVfs->xCall ){ \
@@ -259,9 +248,9 @@ __inline__ unsigned long long int osinst_hwtime(void){
#define OS_TIME_VFS(eEvent, Z, flags, A, B, Call) { \ #define OS_TIME_VFS(eEvent, Z, flags, A, B, Call) { \
InstVfs *pInstVfs = (InstVfs *)pVfs; \ InstVfs *pInstVfs = (InstVfs *)pVfs; \
int rc; \ int rc; \
sqlite3_int64 t = osinst_hwtime(); \ sqlite_uint64 t = sqlite3Hwtime(); \
rc = Call; \ rc = Call; \
t = osinst_hwtime() - t; \ t = sqlite3Hwtime() - t; \
pInstVfs->aTime[eEvent] += t; \ pInstVfs->aTime[eEvent] += t; \
pInstVfs->aCount[eEvent] += 1; \ pInstVfs->aCount[eEvent] += 1; \
if( pInstVfs->xCall ){ \ if( pInstVfs->xCall ){ \

View File

@@ -43,7 +43,7 @@
** in this file for details. If in doubt, do not deviate from existing ** in this file for details. If in doubt, do not deviate from existing
** commenting and indentation practices when changing or adding code. ** commenting and indentation practices when changing or adding code.
** **
** $Id: vdbe.c,v 1.743 2008/05/29 05:23:42 drh Exp $ ** $Id: vdbe.c,v 1.744 2008/05/29 20:22:37 shane Exp $
*/ */
#include "sqliteInt.h" #include "sqliteInt.h"
#include <ctype.h> #include <ctype.h>
@@ -465,18 +465,13 @@ static void registerTrace(FILE *out, int iReg, Mem *p){
#ifdef VDBE_PROFILE #ifdef VDBE_PROFILE
/*
** The following routine only works on pentium-class processors. /*
** It uses the RDTSC opcode to read the cycle count value out of the ** hwtime.h contains inline assembler code for implementing
** processor and returns that value. This can be used for high-res ** high-performance timing routines.
** profiling.
*/ */
__inline__ unsigned long long int hwtime(void){ #include "hwtime.h"
unsigned int lo, hi;
/* We cannot use "=A", since this would use %rax on x86_64 */
__asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi));
return (unsigned long long int)hi << 32 | lo;
}
#endif #endif
/* /*
@@ -536,7 +531,7 @@ int sqlite3VdbeExec(
Mem *pOut; /* Output operand */ Mem *pOut; /* Output operand */
u8 opProperty; u8 opProperty;
#ifdef VDBE_PROFILE #ifdef VDBE_PROFILE
unsigned long long start; /* CPU clock count at start of opcode */ u64 start; /* CPU clock count at start of opcode */
int origPc; /* Program counter at start of opcode */ int origPc; /* Program counter at start of opcode */
#endif #endif
#ifndef SQLITE_OMIT_PROGRESS_CALLBACK #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
@@ -580,7 +575,7 @@ int sqlite3VdbeExec(
if( db->mallocFailed ) goto no_mem; if( db->mallocFailed ) goto no_mem;
#ifdef VDBE_PROFILE #ifdef VDBE_PROFILE
origPc = pc; origPc = pc;
start = hwtime(); start = sqlite3Hwtime();
#endif #endif
pOp = &p->aOp[pc]; pOp = &p->aOp[pc];
@@ -4876,11 +4871,11 @@ default: { /* This is really OP_Noop and OP_Explain */
#ifdef VDBE_PROFILE #ifdef VDBE_PROFILE
{ {
long long elapse = hwtime() - start; u64 elapsed = sqlite3Hwtime() - start;
pOp->cycles += elapse; pOp->cycles += elapsed;
pOp->cnt++; pOp->cnt++;
#if 0 #if 0
fprintf(stdout, "%10lld ", elapse); fprintf(stdout, "%10llu ", elapsed);
sqlite3VdbePrintOp(stdout, origPc, &p->aOp[origPc]); sqlite3VdbePrintOp(stdout, origPc, &p->aOp[origPc]);
#endif #endif
} }

View File

@@ -15,7 +15,7 @@
** or VDBE. The VDBE implements an abstract machine that runs a ** or VDBE. The VDBE implements an abstract machine that runs a
** simple program to access and modify the underlying database. ** simple program to access and modify the underlying database.
** **
** $Id: vdbe.h,v 1.131 2008/05/01 17:03:49 drh Exp $ ** $Id: vdbe.h,v 1.132 2008/05/29 20:22:37 shane Exp $
*/ */
#ifndef _SQLITE_VDBE_H_ #ifndef _SQLITE_VDBE_H_
#define _SQLITE_VDBE_H_ #define _SQLITE_VDBE_H_
@@ -63,11 +63,11 @@ struct VdbeOp {
KeyInfo *pKeyInfo; /* Used when p4type is P4_KEYINFO */ KeyInfo *pKeyInfo; /* Used when p4type is P4_KEYINFO */
} p4; } p4;
#ifdef SQLITE_DEBUG #ifdef SQLITE_DEBUG
char *zComment; /* Comment to improve readability */ char *zComment; /* Comment to improve readability */
#endif #endif
#ifdef VDBE_PROFILE #ifdef VDBE_PROFILE
int cnt; /* Number of times this instruction was executed */ int cnt; /* Number of times this instruction was executed */
long long cycles; /* Total time spend executing this instruction */ u64 cycles; /* Total time spent executing this instruction */
#endif #endif
}; };
typedef struct VdbeOp VdbeOp; typedef struct VdbeOp VdbeOp;

View File

@@ -92,6 +92,7 @@ foreach hdr {
fts3_hash.h fts3_hash.h
fts3_tokenizer.h fts3_tokenizer.h
hash.h hash.h
hwtime.h
keywordhash.h keywordhash.h
mutex.h mutex.h
opcodes.h opcodes.h
@@ -146,7 +147,7 @@ proc copy_file {filename} {
if {[regexp {^#\s*include\s+["<]([^">]+)[">]} $line all hdr]} { if {[regexp {^#\s*include\s+["<]([^">]+)[">]} $line all hdr]} {
if {[info exists available_hdr($hdr)]} { if {[info exists available_hdr($hdr)]} {
if {$available_hdr($hdr)} { if {$available_hdr($hdr)} {
if {$hdr!="os_common.h"} { if {$hdr!="os_common.h" && $hdr!="hwtime.h"} {
set available_hdr($hdr) 0 set available_hdr($hdr) 0
} }
section_comment "Include $hdr in the middle of $tail" section_comment "Include $hdr in the middle of $tail"
@@ -229,7 +230,7 @@ foreach file {
bitvec.c bitvec.c
pager.c pager.c
btmutex.c btmutex.c
btree.c btree.c
vdbefifo.c vdbefifo.c

View File

@@ -56,6 +56,7 @@ foreach hdr {
btree.h btree.h
btreeInt.h btreeInt.h
hash.h hash.h
hwtime.h
keywordhash.h keywordhash.h
opcodes.h opcodes.h
os_common.h os_common.h

View File

@@ -15,7 +15,7 @@
** Then link against this program. But to do optimize this program ** Then link against this program. But to do optimize this program
** because that defeats the hi-res timer. ** because that defeats the hi-res timer.
** **
** gcc speedtest16.c sqlite3.o -ldl ** gcc speedtest16.c sqlite3.o -ldl -I../src
** **
** Then run this program with a single argument which is the name of ** Then run this program with a single argument which is the name of
** a file containing SQL script that you want to test: ** a file containing SQL script that you want to test:
@@ -29,19 +29,11 @@
#include <unistd.h> #include <unistd.h>
#include "sqlite3.h" #include "sqlite3.h"
/*
/* ** hwtime.h contains inline assembler code for implementing
** The following routine only works on pentium-class processors. ** high-performance timing routines.
** It uses the RDTSC opcode to read the cycle count value out of the
** processor and returns that value. This can be used for high-res
** profiling.
*/ */
__inline__ unsigned long long int hwtime(void){ #include "hwtime.h"
unsigned int lo, hi;
/* We cannot use "=A", since this would use %rax on x86_64 */
__asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi));
return (unsigned long long int)hi << 32 | lo;
}
/* /*
** Convert a zero-terminated ASCII string into a zero-terminated ** Convert a zero-terminated ASCII string into a zero-terminated
@@ -64,9 +56,9 @@ static void *asciiToUtf16le(const char *z){
/* /*
** Timers ** Timers
*/ */
static unsigned long long int prepTime = 0; static sqlite_uint64 prepTime = 0;
static unsigned long long int runTime = 0; static sqlite_uint64 runTime = 0;
static unsigned long long int finalizeTime = 0; static sqlite_uint64 finalizeTime = 0;
/* /*
** Prepare and run a single statement of SQL. ** Prepare and run a single statement of SQL.
@@ -75,28 +67,28 @@ static void prepareAndRun(sqlite3 *db, const char *zSql){
void *utf16; void *utf16;
sqlite3_stmt *pStmt; sqlite3_stmt *pStmt;
const void *stmtTail; const void *stmtTail;
unsigned long long int iStart, iElapse; sqlite_uint64 iStart, iElapse;
int rc; int rc;
printf("****************************************************************\n"); printf("****************************************************************\n");
printf("SQL statement: [%s]\n", zSql); printf("SQL statement: [%s]\n", zSql);
utf16 = asciiToUtf16le(zSql); utf16 = asciiToUtf16le(zSql);
iStart = hwtime(); iStart = sqlite3Hwtime();
rc = sqlite3_prepare16_v2(db, utf16, -1, &pStmt, &stmtTail); rc = sqlite3_prepare16_v2(db, utf16, -1, &pStmt, &stmtTail);
iElapse = hwtime() - iStart; iElapse = sqlite3Hwtime() - iStart;
prepTime += iElapse; prepTime += iElapse;
printf("sqlite3_prepare16_v2() returns %d in %llu cycles\n", rc, iElapse); printf("sqlite3_prepare16_v2() returns %d in %llu cycles\n", rc, iElapse);
if( rc==SQLITE_OK ){ if( rc==SQLITE_OK ){
int nRow = 0; int nRow = 0;
iStart = hwtime(); iStart = sqlite3Hwtime();
while( (rc=sqlite3_step(pStmt))==SQLITE_ROW ){ nRow++; } while( (rc=sqlite3_step(pStmt))==SQLITE_ROW ){ nRow++; }
iElapse = hwtime() - iStart; iElapse = sqlite3Hwtime() - iStart;
runTime += iElapse; runTime += iElapse;
printf("sqlite3_step() returns %d after %d rows in %llu cycles\n", printf("sqlite3_step() returns %d after %d rows in %llu cycles\n",
rc, nRow, iElapse); rc, nRow, iElapse);
iStart = hwtime(); iStart = sqlite3Hwtime();
rc = sqlite3_finalize(pStmt); rc = sqlite3_finalize(pStmt);
iElapse = hwtime() - iStart; iElapse = sqlite3Hwtime() - iStart;
finalizeTime += iElapse; finalizeTime += iElapse;
printf("sqlite3_finalize() returns %d in %llu cycles\n", rc, iElapse); printf("sqlite3_finalize() returns %d in %llu cycles\n", rc, iElapse);
} }
@@ -111,8 +103,8 @@ int main(int argc, char **argv){
char *zSql; char *zSql;
int i, j; int i, j;
FILE *in; FILE *in;
unsigned long long int iStart, iElapse; sqlite_uint64 iStart, iElapse;
unsigned long long int iSetup = 0; sqlite_uint64 iSetup = 0;
int nStmt = 0; int nStmt = 0;
int nByte = 0; int nByte = 0;
@@ -133,9 +125,9 @@ int main(int argc, char **argv){
printf("SQLite version: %d\n", sqlite3_libversion_number()); printf("SQLite version: %d\n", sqlite3_libversion_number());
unlink(argv[1]); unlink(argv[1]);
utf16 = asciiToUtf16le(argv[1]); utf16 = asciiToUtf16le(argv[1]);
iStart = hwtime(); iStart = sqlite3Hwtime();
rc = sqlite3_open16(utf16, &db); rc = sqlite3_open16(utf16, &db);
iElapse = hwtime() - iStart; iElapse = sqlite3Hwtime() - iStart;
iSetup = iElapse; iSetup = iElapse;
printf("sqlite3_open16() returns %d in %llu cycles\n", rc, iElapse); printf("sqlite3_open16() returns %d in %llu cycles\n", rc, iElapse);
free(utf16); free(utf16);
@@ -159,9 +151,9 @@ int main(int argc, char **argv){
} }
} }
} }
iStart = hwtime(); iStart = sqlite3Hwtime();
sqlite3_close(db); sqlite3_close(db);
iElapse = hwtime() - iStart; iElapse = sqlite3Hwtime() - iStart;
iSetup += iElapse; iSetup += iElapse;
printf("sqlite3_close() returns in %llu cycles\n", iElapse); printf("sqlite3_close() returns in %llu cycles\n", iElapse);
printf("\n"); printf("\n");

View File

@@ -14,7 +14,7 @@
** Then link against this program. But to do optimize this program ** Then link against this program. But to do optimize this program
** because that defeats the hi-res timer. ** because that defeats the hi-res timer.
** **
** gcc speedtest8.c sqlite3.o -ldl ** gcc speedtest8.c sqlite3.o -ldl -I../src
** **
** Then run this program with a single argument which is the name of ** Then run this program with a single argument which is the name of
** a file containing SQL script that you want to test: ** a file containing SQL script that you want to test:
@@ -25,32 +25,30 @@
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <ctype.h> #include <ctype.h>
#include <time.h>
#if defined(_MSC_VER)
#include <windows.h>
#else
#include <unistd.h> #include <unistd.h>
#include <sys/times.h> #include <sys/times.h>
#include <time.h>
#include <sched.h> #include <sched.h>
#endif
#include "sqlite3.h" #include "sqlite3.h"
/* /*
** The following routine only works on pentium-class processors. ** hwtime.h contains inline assembler code for implementing
** It uses the RDTSC opcode to read the cycle count value out of the ** high-performance timing routines.
** processor and returns that value. This can be used for high-res
** profiling.
*/ */
__inline__ unsigned long long int hwtime(void){ #include "hwtime.h"
unsigned int lo, hi;
/* We cannot use "=A", since this would use %rax on x86_64 */
__asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi));
return (unsigned long long int)hi << 32 | lo;
}
/* /*
** Timers ** Timers
*/ */
static unsigned long long int prepTime = 0; static sqlite_uint64 prepTime = 0;
static unsigned long long int runTime = 0; static sqlite_uint64 runTime = 0;
static unsigned long long int finalizeTime = 0; static sqlite_uint64 finalizeTime = 0;
/* /*
** Prepare and run a single statement of SQL. ** Prepare and run a single statement of SQL.
@@ -58,33 +56,33 @@ static unsigned long long int finalizeTime = 0;
static void prepareAndRun(sqlite3 *db, const char *zSql, int bQuiet){ static void prepareAndRun(sqlite3 *db, const char *zSql, int bQuiet){
sqlite3_stmt *pStmt; sqlite3_stmt *pStmt;
const char *stmtTail; const char *stmtTail;
unsigned long long int iStart, iElapse; sqlite_uint64 iStart, iElapse;
int rc; int rc;
if (!bQuiet){ if (!bQuiet){
printf("***************************************************************\n"); printf("***************************************************************\n");
} }
if (!bQuiet) printf("SQL statement: [%s]\n", zSql); if (!bQuiet) printf("SQL statement: [%s]\n", zSql);
iStart = hwtime(); iStart = sqlite3Hwtime();
rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, &stmtTail); rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, &stmtTail);
iElapse = hwtime() - iStart; iElapse = sqlite3Hwtime() - iStart;
prepTime += iElapse; prepTime += iElapse;
if (!bQuiet){ if (!bQuiet){
printf("sqlite3_prepare_v2() returns %d in %llu cycles\n", rc, iElapse); printf("sqlite3_prepare_v2() returns %d in %llu cycles\n", rc, iElapse);
} }
if( rc==SQLITE_OK ){ if( rc==SQLITE_OK ){
int nRow = 0; int nRow = 0;
iStart = hwtime(); iStart = sqlite3Hwtime();
while( (rc=sqlite3_step(pStmt))==SQLITE_ROW ){ nRow++; } while( (rc=sqlite3_step(pStmt))==SQLITE_ROW ){ nRow++; }
iElapse = hwtime() - iStart; iElapse = sqlite3Hwtime() - iStart;
runTime += iElapse; runTime += iElapse;
if (!bQuiet){ if (!bQuiet){
printf("sqlite3_step() returns %d after %d rows in %llu cycles\n", printf("sqlite3_step() returns %d after %d rows in %llu cycles\n",
rc, nRow, iElapse); rc, nRow, iElapse);
} }
iStart = hwtime(); iStart = sqlite3Hwtime();
rc = sqlite3_finalize(pStmt); rc = sqlite3_finalize(pStmt);
iElapse = hwtime() - iStart; iElapse = sqlite3Hwtime() - iStart;
finalizeTime += iElapse; finalizeTime += iElapse;
if (!bQuiet){ if (!bQuiet){
printf("sqlite3_finalize() returns %d in %llu cycles\n", rc, iElapse); printf("sqlite3_finalize() returns %d in %llu cycles\n", rc, iElapse);
@@ -182,14 +180,16 @@ int main(int argc, char **argv){
char *zSql; char *zSql;
int i, j; int i, j;
FILE *in; FILE *in;
unsigned long long int iStart, iElapse; sqlite_uint64 iStart, iElapse;
unsigned long long int iSetup = 0; sqlite_uint64 iSetup = 0;
int nStmt = 0; int nStmt = 0;
int nByte = 0; int nByte = 0;
const char *zArgv0 = argv[0]; const char *zArgv0 = argv[0];
int bQuiet = 0; int bQuiet = 0;
#if !defined(_MSC_VER)
struct tms tmsStart, tmsEnd; struct tms tmsStart, tmsEnd;
clock_t clkStart, clkEnd; clock_t clkStart, clkEnd;
#endif
#ifdef HAVE_OSINST #ifdef HAVE_OSINST
extern sqlite3_vfs *sqlite3_instvfs_binarylog(char *, char *, char *); extern sqlite3_vfs *sqlite3_instvfs_binarylog(char *, char *, char *);
@@ -223,6 +223,18 @@ int main(int argc, char **argv){
** equates to "Normal". ** equates to "Normal".
*/ */
if( argc>4 && (strcmp(argv[1], "-priority")==0) ){ if( argc>4 && (strcmp(argv[1], "-priority")==0) ){
#if defined(_MSC_VER)
int new_priority = atoi(argv[2]);
if(!SetPriorityClass(GetCurrentProcess(),
(new_priority<=-5) ? HIGH_PRIORITY_CLASS :
(new_priority<=0) ? ABOVE_NORMAL_PRIORITY_CLASS :
(new_priority==0) ? NORMAL_PRIORITY_CLASS :
(new_priority<5) ? BELOW_NORMAL_PRIORITY_CLASS :
IDLE_PRIORITY_CLASS)){
printf ("error setting priority\n");
exit(2);
}
#else
struct sched_param myParam; struct sched_param myParam;
sched_getparam(0, &myParam); sched_getparam(0, &myParam);
printf ("Current process priority is %d.\n", (int)myParam.sched_priority); printf ("Current process priority is %d.\n", (int)myParam.sched_priority);
@@ -232,6 +244,7 @@ int main(int argc, char **argv){
printf ("error setting priority\n"); printf ("error setting priority\n");
exit(2); exit(2);
} }
#endif
argv += 2; argv += 2;
argc -= 2; argc -= 2;
continue; continue;
@@ -271,10 +284,12 @@ int main(int argc, char **argv){
printf("SQLite version: %d\n", sqlite3_libversion_number()); printf("SQLite version: %d\n", sqlite3_libversion_number());
unlink(argv[1]); unlink(argv[1]);
#if !defined(_MSC_VER)
clkStart = times(&tmsStart); clkStart = times(&tmsStart);
iStart = hwtime(); #endif
iStart = sqlite3Hwtime();
rc = sqlite3_open(argv[1], &db); rc = sqlite3_open(argv[1], &db);
iElapse = hwtime() - iStart; iElapse = sqlite3Hwtime() - iStart;
iSetup = iElapse; iSetup = iElapse;
if (!bQuiet) printf("sqlite3_open() returns %d in %llu cycles\n", rc, iElapse); if (!bQuiet) printf("sqlite3_open() returns %d in %llu cycles\n", rc, iElapse);
for(i=j=0; j<nSql; j++){ for(i=j=0; j<nSql; j++){
@@ -299,10 +314,12 @@ int main(int argc, char **argv){
} }
} }
} }
iStart = hwtime(); iStart = sqlite3Hwtime();
sqlite3_close(db); sqlite3_close(db);
iElapse = hwtime() - iStart; iElapse = sqlite3Hwtime() - iStart;
#if !defined(_MSC_VER)
clkEnd = times(&tmsEnd); clkEnd = times(&tmsEnd);
#endif
iSetup += iElapse; iSetup += iElapse;
if (!bQuiet) printf("sqlite3_close() returns in %llu cycles\n", iElapse); if (!bQuiet) printf("sqlite3_close() returns in %llu cycles\n", iElapse);
@@ -316,10 +333,12 @@ int main(int argc, char **argv){
printf("Total time: %15llu cycles\n", printf("Total time: %15llu cycles\n",
prepTime + runTime + finalizeTime + iSetup); prepTime + runTime + finalizeTime + iSetup);
#if !defined(_MSC_VER)
printf("\n"); printf("\n");
printf("Total user CPU time: %15.3g secs\n", (tmsEnd.tms_utime - tmsStart.tms_utime)/(double)CLOCKS_PER_SEC ); printf("Total user CPU time: %15.3g secs\n", (tmsEnd.tms_utime - tmsStart.tms_utime)/(double)CLOCKS_PER_SEC );
printf("Total system CPU time: %15.3g secs\n", (tmsEnd.tms_stime - tmsStart.tms_stime)/(double)CLOCKS_PER_SEC ); printf("Total system CPU time: %15.3g secs\n", (tmsEnd.tms_stime - tmsStart.tms_stime)/(double)CLOCKS_PER_SEC );
printf("Total real time: %15.3g secs\n", (clkEnd -clkStart)/(double)CLOCKS_PER_SEC ); printf("Total real time: %15.3g secs\n", (clkEnd -clkStart)/(double)CLOCKS_PER_SEC );
#endif
#ifdef HAVE_OSINST #ifdef HAVE_OSINST
if( pVfs ){ if( pVfs ){

View File

@@ -14,7 +14,7 @@
** Then link against this program. But to do optimize this program ** Then link against this program. But to do optimize this program
** because that defeats the hi-res timer. ** because that defeats the hi-res timer.
** **
** gcc speedtest8.c sqlite3.o -ldl ** gcc speedtest8.c sqlite3.o -ldl -I../src
** **
** Then run this program with a single argument which is the name of ** Then run this program with a single argument which is the name of
** a file containing SQL script that you want to test: ** a file containing SQL script that you want to test:
@@ -29,18 +29,11 @@
#include <stdarg.h> #include <stdarg.h>
#include "sqlite3.h" #include "sqlite3.h"
/* /*
** The following routine only works on pentium-class processors. ** hwtime.h contains inline assembler code for implementing
** It uses the RDTSC opcode to read the cycle count value out of the ** high-performance timing routines.
** processor and returns that value. This can be used for high-res
** profiling.
*/ */
__inline__ sqlite3_uint64 hwtime(void){ #include "hwtime.h"
unsigned int lo, hi;
/* We cannot use "=A", since this would use %rax on x86_64 */
__asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi));
return (sqlite3_uint64)hi << 32 | lo;
}
/* /*
** Send a message to the log file. ** Send a message to the log file.
@@ -136,24 +129,25 @@ static sqlite3_io_methods inst_io_methods = {
}; };
#define OS_TIME_IO(MESSAGE, A, B, CALL) \ #define OS_TIME_IO(MESSAGE, A, B, CALL) \
int rc; sqlite3_uint64 t1, t2; \ int rc; \
sqlite_uint64 t1, t2; \
inst_file *p = (inst_file*)pFile; \ inst_file *p = (inst_file*)pFile; \
t1 = hwtime(); \ t1 = sqlite3Hwtime(); \
rc = CALL; \ rc = CALL; \
t2 = hwtime(); \ t2 = sqlite3Hwtime(); \
logMessage(MESSAGE, A, B, t2-t1); \ logMessage(MESSAGE, A, B, t2-t1); \
instTime += hwtime() - t2; \ instTime += sqlite3Hwtime() - t2; \
return rc; return rc;
#define OS_TIME_VFS(MESSAGE, A, B, CALL) \ #define OS_TIME_VFS(MESSAGE, A, B, CALL) \
int rc; \ int rc; \
sqlite3_uint64 t1, t2; \ sqlite_uint64 t1, t2; \
sqlite3_vfs *pRealVfs = (sqlite3_vfs*)pVfs->pAppData; \ sqlite3_vfs *pRealVfs = (sqlite3_vfs*)pVfs->pAppData; \
t1 = hwtime(); \ t1 = sqlite3Hwtime(); \
rc = CALL; \ rc = CALL; \
t2 = hwtime(); \ t2 = sqlite3Hwtime(); \
logMessage(MESSAGE, A, B, t2-t1); \ logMessage(MESSAGE, A, B, t2-t1); \
instTime += hwtime() - t2; \ instTime += sqlite3Hwtime() - t2; \
return rc; return rc;
@@ -437,32 +431,32 @@ static void setupInstrumentedVfs(void){
static void prepareAndRun(sqlite3 *db, const char *zSql){ static void prepareAndRun(sqlite3 *db, const char *zSql){
sqlite3_stmt *pStmt; sqlite3_stmt *pStmt;
const char *stmtTail; const char *stmtTail;
sqlite3_uint64 iStart, iElapse; sqlite_uint64 iStart, iElapse;
int rc; int rc;
printf("****************************************************************\n"); printf("****************************************************************\n");
printf("SQL statement: [%s]\n", zSql); printf("SQL statement: [%s]\n", zSql);
instTime = 0; instTime = 0;
iStart = hwtime(); iStart = sqlite3Hwtime();
rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, &stmtTail); rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, &stmtTail);
iElapse = hwtime(); iElapse = sqlite3Hwtime();
iElapse -= iStart + instTime; iElapse -= iStart + instTime;
prepTime += iElapse; prepTime += iElapse;
printf("sqlite3_prepare_v2() returns %d in %llu cycles\n", rc, iElapse); printf("sqlite3_prepare_v2() returns %d in %llu cycles\n", rc, iElapse);
if( rc==SQLITE_OK ){ if( rc==SQLITE_OK ){
int nRow = 0; int nRow = 0;
instTime = 0; instTime = 0;
iStart = hwtime(); iStart = sqlite3Hwtime();
while( (rc=sqlite3_step(pStmt))==SQLITE_ROW ){ nRow++; } while( (rc=sqlite3_step(pStmt))==SQLITE_ROW ){ nRow++; }
iElapse = hwtime(); iElapse = sqlite3Hwtime();
iElapse -= iStart + instTime; iElapse -= iStart + instTime;
runTime += iElapse; runTime += iElapse;
printf("sqlite3_step() returns %d after %d rows in %llu cycles\n", printf("sqlite3_step() returns %d after %d rows in %llu cycles\n",
rc, nRow, iElapse); rc, nRow, iElapse);
instTime = 0; instTime = 0;
iStart = hwtime(); iStart = sqlite3Hwtime();
rc = sqlite3_finalize(pStmt); rc = sqlite3_finalize(pStmt);
iElapse = hwtime(); iElapse = sqlite3Hwtime();
iElapse -= iStart + instTime; iElapse -= iStart + instTime;
finalizeTime += iElapse; finalizeTime += iElapse;
printf("sqlite3_finalize() returns %d in %llu cycles\n", rc, iElapse); printf("sqlite3_finalize() returns %d in %llu cycles\n", rc, iElapse);
@@ -476,8 +470,8 @@ int main(int argc, char **argv){
char *zSql; char *zSql;
int i, j; int i, j;
FILE *in; FILE *in;
sqlite3_uint64 iStart, iElapse; sqlite_uint64 iStart, iElapse;
sqlite3_uint64 iSetup = 0; sqlite_uint64 iSetup = 0;
int nStmt = 0; int nStmt = 0;
int nByte = 0; int nByte = 0;
@@ -499,9 +493,9 @@ int main(int argc, char **argv){
unlink(argv[1]); unlink(argv[1]);
setupInstrumentedVfs(); setupInstrumentedVfs();
instTime = 0; instTime = 0;
iStart = hwtime(); iStart = sqlite3Hwtime();
rc = sqlite3_open(argv[1], &db); rc = sqlite3_open(argv[1], &db);
iElapse = hwtime(); iElapse = sqlite3Hwtime();
iElapse -= iStart + instTime; iElapse -= iStart + instTime;
iSetup = iElapse; iSetup = iElapse;
printf("sqlite3_open() returns %d in %llu cycles\n", rc, iElapse); printf("sqlite3_open() returns %d in %llu cycles\n", rc, iElapse);
@@ -526,9 +520,9 @@ int main(int argc, char **argv){
} }
} }
instTime = 0; instTime = 0;
iStart = hwtime(); iStart = sqlite3Hwtime();
sqlite3_close(db); sqlite3_close(db);
iElapse = hwtime(); iElapse = sqlite3Hwtime();
iElapse -= iStart + instTime; iElapse -= iStart + instTime;
iSetup += iElapse; iSetup += iElapse;
printf("sqlite3_close() returns in %llu cycles\n", iElapse); printf("sqlite3_close() returns in %llu cycles\n", iElapse);