/ Check-in [9883b406]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment: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)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 9883b406ce24eae93942ee5e6aab33fb6b05329f
User & Date: shane 2008-05-29 20:22:36
Original User & Date: shane 2008-05-29 20:22:37
Context
2008-05-29
20:22
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 5179) check-in: 19f5f571 user: shane tags: trunk
20:22
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) check-in: 9883b406 user: shane tags: trunk
05:23
Fix cosmetic issues spotted while working on ticket #3146 (CVS 5177) check-in: 5f6eab65 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to Makefile.in.

   190    190     $(TOP)/src/date.c \
   191    191     $(TOP)/src/delete.c \
   192    192     $(TOP)/src/expr.c \
   193    193     $(TOP)/src/fault.c \
   194    194     $(TOP)/src/func.c \
   195    195     $(TOP)/src/hash.c \
   196    196     $(TOP)/src/hash.h \
          197  +  $(TOP)/src/hwtime.h \
   197    198     $(TOP)/src/insert.c \
   198    199     $(TOP)/src/journal.c \
   199    200     $(TOP)/src/legacy.c \
   200    201     $(TOP)/src/loadext.c \
   201    202     $(TOP)/src/main.c \
   202    203     $(TOP)/src/malloc.c \
   203    204     $(TOP)/src/mem1.c \
................................................................................
   358    359   # Header files used by all library source files.
   359    360   #
   360    361   HDR = \
   361    362      sqlite3.h  \
   362    363      $(TOP)/src/btree.h \
   363    364      $(TOP)/src/btreeInt.h \
   364    365      $(TOP)/src/hash.h \
          366  +   $(TOP)/src/hwtime.h \
   365    367      $(TOP)/src/sqliteLimit.h \
   366    368      $(TOP)/src/mutex.h \
   367    369      opcodes.h \
   368    370      $(TOP)/src/os.h \
   369    371      $(TOP)/src/os_common.h \
   370    372      $(TOP)/src/sqlite3ext.h \
   371    373      $(TOP)/src/sqliteInt.h  \

Changes to main.mk.

    97     97     $(TOP)/src/date.c \
    98     98     $(TOP)/src/delete.c \
    99     99     $(TOP)/src/expr.c \
   100    100     $(TOP)/src/fault.c \
   101    101     $(TOP)/src/func.c \
   102    102     $(TOP)/src/hash.c \
   103    103     $(TOP)/src/hash.h \
          104  +  $(TOP)/src/hwtime.h \
   104    105     $(TOP)/src/insert.c \
   105    106     $(TOP)/src/journal.c \
   106    107     $(TOP)/src/legacy.c \
   107    108     $(TOP)/src/loadext.c \
   108    109     $(TOP)/src/main.c \
   109    110     $(TOP)/src/malloc.c \
   110    111     $(TOP)/src/mem1.c \
................................................................................
   246    247   
   247    248   # Header files used by all library source files.
   248    249   #
   249    250   HDR = \
   250    251      $(TOP)/src/btree.h \
   251    252      $(TOP)/src/btreeInt.h \
   252    253      $(TOP)/src/hash.h \
          254  +   $(TOP)/src/hwtime.h \
   253    255      keywordhash.h \
   254    256      $(TOP)/src/mutex.h \
   255    257      opcodes.h \
   256    258      $(TOP)/src/os.h \
   257    259      $(TOP)/src/os_common.h \
   258    260      $(TOP)/src/pager.h \
   259    261      parse.h  \

Added src/hwtime.h.

            1  +/*
            2  +** 2008 May 27
            3  +**
            4  +** The author disclaims copyright to this source code.  In place of
            5  +** a legal notice, here is a blessing:
            6  +**
            7  +**    May you do good and not evil.
            8  +**    May you find forgiveness for yourself and forgive others.
            9  +**    May you share freely, never taking more than you give.
           10  +**
           11  +******************************************************************************
           12  +**
           13  +** This file contains inline asm code for retrieving "high-performance"
           14  +** counters for x86 class CPUs.
           15  +**
           16  +** $Id: hwtime.h,v 1.1 2008/05/29 20:22:37 shane Exp $
           17  +*/
           18  +#ifndef _HWTIME_H_
           19  +#define _HWTIME_H_
           20  +
           21  +/*
           22  +** The following routine only works on pentium-class (or newer) processors.
           23  +** It uses the RDTSC opcode to read the cycle count value out of the
           24  +** processor and returns that value.  This can be used for high-res
           25  +** profiling.
           26  +*/
           27  +#if (defined(__GNUC__) || defined(_MSC_VER)) && \
           28  +      (defined(i386) || defined(__i386__) || defined(_M_IX86))
           29  +
           30  +  #if defined(__GNUC__)
           31  +
           32  +  __inline__ sqlite_uint64 sqlite3Hwtime(void){
           33  +     unsigned int lo, hi;
           34  +     /* We cannot use "=A", since this would use %rax on x86_64 */
           35  +     __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi));
           36  +     return (sqlite_uint64)hi << 32 | lo;
           37  +  }
           38  +
           39  +  #elif defined(_MSC_VER)
           40  +
           41  +  __declspec(naked) __inline sqlite_uint64 __cdecl sqlite3Hwtime(void){
           42  +     __asm {
           43  +        rdtsc
           44  +        ret       ; return value at EDX:EAX
           45  +     }
           46  +  }
           47  +
           48  +  #endif
           49  +
           50  +#else
           51  +
           52  +  #error Need implementation of sqlite3Hwtime() for your platform.
           53  +
           54  +  /*
           55  +  ** To compile without implementing sqlite3Hwtime() for your platform,
           56  +  ** you can remove the above #error and use the following
           57  +  ** stub function.  You will lose timing support for many
           58  +  ** of the debugging and testing utilities, but it should at
           59  +  ** least compile and run.
           60  +  */
           61  +  sqlite_uint64 sqlite3Hwtime(void){ return ((sqlite_uint64)0); }
           62  +
           63  +#endif
           64  +
           65  +#endif /* !defined(_HWTIME_H_) */

Changes to src/os_common.h.

    13     13   ** This file contains macros and a little bit of code that is common to
    14     14   ** all of the platform-specific files (os_*.c) and is #included into those
    15     15   ** files.
    16     16   **
    17     17   ** This file should be #included by the os_*.c files only.  It is not a
    18     18   ** general purpose header file.
    19     19   **
    20         -** $Id: os_common.h,v 1.36 2008/05/16 04:51:55 danielk1977 Exp $
           20  +** $Id: os_common.h,v 1.37 2008/05/29 20:22:37 shane Exp $
    21     21   */
           22  +#ifndef _OS_COMMON_H_
           23  +#define _OS_COMMON_H_
    22     24   
    23     25   /*
    24     26   ** At least two bugs have slipped in because we changed the MEMORY_DEBUG
    25     27   ** macro to SQLITE_DEBUG and some older makefiles have not yet made the
    26     28   ** switch.  The following code should catch this problem at compile-time.
    27     29   */
    28     30   #ifdef MEMORY_DEBUG
................................................................................
    60     62   #endif
    61     63   
    62     64   /*
    63     65   ** Macros for performance tracing.  Normally turned off.  Only works
    64     66   ** on i486 hardware.
    65     67   */
    66     68   #ifdef SQLITE_PERFORMANCE_TRACE
    67         -__inline__ unsigned long long int hwtime(void){
    68         -  unsigned long long int x;
    69         -  __asm__("rdtsc\n\t"
    70         -          "mov %%edx, %%ecx\n\t"
    71         -          :"=A" (x));
    72         -  return x;
    73         -}
    74         -static unsigned long long int g_start;
    75         -static unsigned int elapse;
    76         -#define TIMER_START       g_start=hwtime()
    77         -#define TIMER_END         elapse=hwtime()-g_start
    78         -#define TIMER_ELAPSED     elapse
           69  +
           70  +/* 
           71  +** hwtime.h contains inline assembler code for implementing 
           72  +** high-performance timing routines.
           73  +*/
           74  +#include "hwtime.h"
           75  +
           76  +static sqlite_uint64 g_start;
           77  +static sqlite_uint64 g_elapsed;
           78  +#define TIMER_START       g_start=sqlite3Hwtime()
           79  +#define TIMER_END         g_elapsed=sqlite3Hwtime()-g_start
           80  +#define TIMER_ELAPSED     g_elapsed
    79     81   #else
    80     82   #define TIMER_START
    81     83   #define TIMER_END
    82         -#define TIMER_ELAPSED     0
           84  +#define TIMER_ELAPSED     ((sqlite_uint64)0)
    83     85   #endif
    84     86   
    85     87   /*
    86     88   ** If we compile with the SQLITE_TEST macro set, then the following block
    87     89   ** of code will give us the ability to simulate a disk I/O error.  This
    88     90   ** is used for testing the I/O recovery logic.
    89     91   */
................................................................................
   127    129   */
   128    130   #ifdef SQLITE_TEST
   129    131   int sqlite3_open_file_count = 0;
   130    132   #define OpenCounter(X)  sqlite3_open_file_count+=(X)
   131    133   #else
   132    134   #define OpenCounter(X)
   133    135   #endif
          136  +
          137  +#endif /* !defined(_OS_COMMON_H_) */

Changes to src/os_unix.c.

     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   ******************************************************************************
    12     12   **
    13     13   ** This file contains code that is specific to Unix systems.
    14     14   **
    15         -** $Id: os_unix.c,v 1.182 2008/05/16 04:51:55 danielk1977 Exp $
           15  +** $Id: os_unix.c,v 1.183 2008/05/29 20:22:37 shane Exp $
    16     16   */
    17     17   #include "sqliteInt.h"
    18     18   #if OS_UNIX              /* This file is used on unix only */
    19     19   
    20     20   /* #define SQLITE_ENABLE_LOCKING_STYLE 0 */
    21     21   
    22     22   /*
................................................................................
   801    801     SimulateIOError( newOffset-- );
   802    802     if( newOffset!=offset ){
   803    803       return -1;
   804    804     }
   805    805     got = read(id->h, pBuf, cnt);
   806    806   #endif
   807    807     TIMER_END;
   808         -  OSTRACE5("READ    %-3d %5d %7lld %d\n", id->h, got, offset, TIMER_ELAPSED);
          808  +  OSTRACE5("READ    %-3d %5d %7lld %llu\n", id->h, got, offset, TIMER_ELAPSED);
   809    809     return got;
   810    810   }
   811    811   
   812    812   /*
   813    813   ** Read data from a file into a buffer.  Return SQLITE_OK if all
   814    814   ** bytes were read successfully and SQLITE_IOERR if anything goes
   815    815   ** wrong.
................................................................................
   849    849     newOffset = lseek(id->h, offset, SEEK_SET);
   850    850     if( newOffset!=offset ){
   851    851       return -1;
   852    852     }
   853    853     got = write(id->h, pBuf, cnt);
   854    854   #endif
   855    855     TIMER_END;
   856         -  OSTRACE5("WRITE   %-3d %5d %7lld %d\n", id->h, got, offset, TIMER_ELAPSED);
          856  +  OSTRACE5("WRITE   %-3d %5d %7lld %llu\n", id->h, got, offset, TIMER_ELAPSED);
   857    857     return got;
   858    858   }
   859    859   
   860    860   
   861    861   /*
   862    862   ** Write data from a buffer into a file.  Return SQLITE_OK on success
   863    863   ** or some other error code on failure.

Changes to src/test_osinst.c.

    10     10   **
    11     11   ******************************************************************************
    12     12   **
    13     13   ** This file contains the implementation of an SQLite vfs wrapper that
    14     14   ** adds instrumentation to all vfs and file methods. C and Tcl interfaces
    15     15   ** are provided to control the instrumentation.
    16     16   **
    17         -** $Id: test_osinst.c,v 1.11 2008/05/16 04:51:55 danielk1977 Exp $
           17  +** $Id: test_osinst.c,v 1.12 2008/05/29 20:22:37 shane Exp $
    18     18   */
    19     19   
    20     20   /*
    21     21   ** C interface:
    22     22   **
    23     23   **   sqlite3_instvfs_create()
    24     24   **   sqlite3_instvfs_destroy()
................................................................................
    49     49   **       been created by an earlier invocation of [sqlite3_instvfs create].
    50     50   **       After a callback script has been configured, it is invoked each
    51     51   **       time a vfs or file method is called by SQLite. Before invoking
    52     52   **       the callback script, five arguments are appended to it:
    53     53   **
    54     54   **         * The name of the invoked method - i.e. "xRead".
    55     55   **
    56         -**         * The time consumed by the method call as measured by hwtime() (an
    57         -**           integer value)
           56  +**         * The time consumed by the method call as measured by 
           57  +**           sqlite3Hwtime() (an integer value)
    58     58   **
    59     59   **         * A string value with a different meaning for different calls. 
    60     60   **           For file methods, the name of the file being operated on. For
    61     61   **           other methods it is the filename argument, if any.
    62     62   **
    63     63   **         * A 32-bit integer value with a call-specific meaning.
    64     64   **
................................................................................
    78     78   **       with vfs $NAME. The report format is a list with one element
    79     79   **       for each method call (xWrite, xRead etc.). Each element is
    80     80   **       itself a list with three elements:
    81     81   **
    82     82   **         * The name of the method call - i.e. "xWrite",
    83     83   **         * The total number of calls to the method (an integer).
    84     84   **         * The aggregate time consumed by all calls to the method as
    85         -**           measured by hwtime() (an integer).
           85  +**           measured by sqlite3Hwtime() (an integer).
    86     86   */
    87     87   
    88     88   #include "sqlite3.h"
    89     89   #include <string.h>
    90     90   #include <assert.h>
    91     91   
    92     92   /*
................................................................................
   218    218     instUnlock,                     /* xUnlock */
   219    219     instCheckReservedLock,          /* xCheckReservedLock */
   220    220     instFileControl,                /* xFileControl */
   221    221     instSectorSize,                 /* xSectorSize */
   222    222     instDeviceCharacteristics       /* xDeviceCharacteristics */
   223    223   };
   224    224   
   225         -/*
   226         -** The following routine only works on pentium-class processors.
   227         -** It uses the RDTSC opcode to read the cycle count value out of the
   228         -** processor and returns that value.  This can be used for high-res
   229         -** profiling.
          225  +/* 
          226  +** hwtime.h contains inline assembler code for implementing 
          227  +** high-performance timing routines.
   230    228   */
   231         -#if defined(i386) || defined(__i386__) || defined(_M_IX86)
   232         -__inline__ unsigned long long int osinst_hwtime(void){
   233         -   unsigned int lo, hi;
   234         -   /* We cannot use "=A", since this would use %rax on x86_64 */
   235         -   __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi));
   236         -   return (unsigned long long int)hi << 32 | lo;
   237         -}
   238         -#else
   239         -  static unsigned long long int osinst_hwtime(void){ return 0; }
   240         -#endif
          229  +#include "hwtime.h"
   241    230   
   242    231   #define OS_TIME_IO(eEvent, A, B, Call) {     \
   243    232     inst_file *p = (inst_file *)pFile;         \
   244    233     InstVfs *pInstVfs = p->pInstVfs;           \
   245    234     int rc;                                    \
   246         -  sqlite3_int64 t = osinst_hwtime();         \
          235  +  sqlite_uint64 t = sqlite3Hwtime();         \
   247    236     rc = Call;                                 \
   248         -  t = osinst_hwtime() - t;                   \
          237  +  t = sqlite3Hwtime() - t;                   \
   249    238     pInstVfs->aTime[eEvent] += t;              \
   250    239     pInstVfs->aCount[eEvent] += 1;             \
   251    240     if( pInstVfs->xCall ){                     \
   252    241       pInstVfs->xCall(                         \
   253    242         pInstVfs->pClient,eEvent,p->iFileId,t,rc,p->zName,p->flags,A,B  \
   254    243       );                                       \
   255    244     }                                          \
   256    245     return rc;                                 \
   257    246   }
   258    247   
   259    248   #define OS_TIME_VFS(eEvent, Z, flags, A, B, Call) {      \
   260    249     InstVfs *pInstVfs = (InstVfs *)pVfs;   \
   261    250     int rc;                                \
   262         -  sqlite3_int64 t = osinst_hwtime();     \
          251  +  sqlite_uint64 t = sqlite3Hwtime();     \
   263    252     rc = Call;                             \
   264         -  t = osinst_hwtime() - t;               \
          253  +  t = sqlite3Hwtime() - t;               \
   265    254     pInstVfs->aTime[eEvent] += t;          \
   266    255     pInstVfs->aCount[eEvent] += 1;         \
   267    256     if( pInstVfs->xCall ){                 \
   268    257       pInstVfs->xCall(pInstVfs->pClient,eEvent,0, t, rc, Z, flags, A, B); \
   269    258     }                                      \
   270    259     return rc;                             \
   271    260   }

Changes to src/vdbe.c.

    39     39   **
    40     40   ** Various scripts scan this source file in order to generate HTML
    41     41   ** documentation, headers files, or other derived files.  The formatting
    42     42   ** of the code in this file is, therefore, important.  See other comments
    43     43   ** in this file for details.  If in doubt, do not deviate from existing
    44     44   ** commenting and indentation practices when changing or adding code.
    45     45   **
    46         -** $Id: vdbe.c,v 1.743 2008/05/29 05:23:42 drh Exp $
           46  +** $Id: vdbe.c,v 1.744 2008/05/29 20:22:37 shane Exp $
    47     47   */
    48     48   #include "sqliteInt.h"
    49     49   #include <ctype.h>
    50     50   #include "vdbeInt.h"
    51     51   
    52     52   /*
    53     53   ** The following global variable is incremented every time a cursor
................................................................................
   461    461   #  define REGISTER_TRACE(R,M) if(p->trace&&R>0)registerTrace(p->trace,R,M)
   462    462   #else
   463    463   #  define REGISTER_TRACE(R,M)
   464    464   #endif
   465    465   
   466    466   
   467    467   #ifdef VDBE_PROFILE
   468         -/*
   469         -** The following routine only works on pentium-class processors.
   470         -** It uses the RDTSC opcode to read the cycle count value out of the
   471         -** processor and returns that value.  This can be used for high-res
   472         -** profiling.
          468  +
          469  +/* 
          470  +** hwtime.h contains inline assembler code for implementing 
          471  +** high-performance timing routines.
   473    472   */
   474         -__inline__ unsigned long long int hwtime(void){
   475         -   unsigned int lo, hi;
   476         -   /* We cannot use "=A", since this would use %rax on x86_64 */
   477         -   __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi));
   478         -   return (unsigned long long int)hi << 32 | lo;
   479         -}
          473  +#include "hwtime.h"
          474  +
   480    475   #endif
   481    476   
   482    477   /*
   483    478   ** The CHECK_FOR_INTERRUPT macro defined here looks to see if the
   484    479   ** sqlite3_interrupt() routine has been called.  If it has been, then
   485    480   ** processing of the VDBE program is interrupted.
   486    481   **
................................................................................
   532    527     int rc = SQLITE_OK;        /* Value to return */
   533    528     sqlite3 *db = p->db;       /* The database */
   534    529     u8 encoding = ENC(db);     /* The database encoding */
   535    530     Mem *pIn1, *pIn2, *pIn3;   /* Input operands */
   536    531     Mem *pOut;                 /* Output operand */
   537    532     u8 opProperty;
   538    533   #ifdef VDBE_PROFILE
   539         -  unsigned long long start;  /* CPU clock count at start of opcode */
          534  +  u64 start;                 /* CPU clock count at start of opcode */
   540    535     int origPc;                /* Program counter at start of opcode */
   541    536   #endif
   542    537   #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
   543    538     int nProgressOps = 0;      /* Opcodes executed since progress callback. */
   544    539   #endif
   545    540   
   546    541     assert( p->magic==VDBE_MAGIC_RUN );  /* sqlite3_step() verifies this */
................................................................................
   576    571     sqlite3FaultEndBenign(-1);
   577    572   #endif
   578    573     for(pc=p->pc; rc==SQLITE_OK; pc++){
   579    574       assert( pc>=0 && pc<p->nOp );
   580    575       if( db->mallocFailed ) goto no_mem;
   581    576   #ifdef VDBE_PROFILE
   582    577       origPc = pc;
   583         -    start = hwtime();
          578  +    start = sqlite3Hwtime();
   584    579   #endif
   585    580       pOp = &p->aOp[pc];
   586    581   
   587    582       /* Only allow tracing if SQLITE_DEBUG is defined.
   588    583       */
   589    584   #ifdef SQLITE_DEBUG
   590    585       if( p->trace ){
................................................................................
  4872   4867   ** readability.  From this point on down, the normal indentation rules are
  4873   4868   ** restored.
  4874   4869   *****************************************************************************/
  4875   4870       }
  4876   4871   
  4877   4872   #ifdef VDBE_PROFILE
  4878   4873       {
  4879         -      long long elapse = hwtime() - start;
  4880         -      pOp->cycles += elapse;
         4874  +      u64 elapsed = sqlite3Hwtime() - start;
         4875  +      pOp->cycles += elapsed;
  4881   4876         pOp->cnt++;
  4882   4877   #if 0
  4883         -        fprintf(stdout, "%10lld ", elapse);
         4878  +        fprintf(stdout, "%10llu ", elapsed);
  4884   4879           sqlite3VdbePrintOp(stdout, origPc, &p->aOp[origPc]);
  4885   4880   #endif
  4886   4881       }
  4887   4882   #endif
  4888   4883   
  4889   4884       /* The following code adds nothing to the actual functionality
  4890   4885       ** of the program.  It is only here for testing and debugging.

Changes to src/vdbe.h.

    11     11   *************************************************************************
    12     12   ** Header file for the Virtual DataBase Engine (VDBE)
    13     13   **
    14     14   ** This header defines the interface to the virtual database engine
    15     15   ** or VDBE.  The VDBE implements an abstract machine that runs a
    16     16   ** simple program to access and modify the underlying database.
    17     17   **
    18         -** $Id: vdbe.h,v 1.131 2008/05/01 17:03:49 drh Exp $
           18  +** $Id: vdbe.h,v 1.132 2008/05/29 20:22:37 shane Exp $
    19     19   */
    20     20   #ifndef _SQLITE_VDBE_H_
    21     21   #define _SQLITE_VDBE_H_
    22     22   #include <stdio.h>
    23     23   
    24     24   /*
    25     25   ** A single VDBE is an opaque structure named "Vdbe".  Only routines
................................................................................
    59     59       VdbeFunc *pVdbeFunc;   /* Used when p4type is P4_VDBEFUNC */
    60     60       CollSeq *pColl;        /* Used when p4type is P4_COLLSEQ */
    61     61       Mem *pMem;             /* Used when p4type is P4_MEM */
    62     62       sqlite3_vtab *pVtab;   /* Used when p4type is P4_VTAB */
    63     63       KeyInfo *pKeyInfo;     /* Used when p4type is P4_KEYINFO */
    64     64     } p4;
    65     65   #ifdef SQLITE_DEBUG
    66         -  char *zComment;     /* Comment to improve readability */
           66  +  char *zComment;          /* Comment to improve readability */
    67     67   #endif
    68     68   #ifdef VDBE_PROFILE
    69         -  int cnt;            /* Number of times this instruction was executed */
    70         -  long long cycles;   /* Total time spend executing this instruction */
           69  +  int cnt;                 /* Number of times this instruction was executed */
           70  +  u64 cycles;              /* Total time spent executing this instruction */
    71     71   #endif
    72     72   };
    73     73   typedef struct VdbeOp VdbeOp;
    74     74   
    75     75   /*
    76     76   ** A smaller version of VdbeOp used for the VdbeAddOpList() function because
    77     77   ** it takes up less space.

Changes to tool/mksqlite3c.tcl.

    88     88   foreach hdr {
    89     89      btree.h
    90     90      btreeInt.h
    91     91      fts3.h
    92     92      fts3_hash.h
    93     93      fts3_tokenizer.h
    94     94      hash.h
           95  +   hwtime.h
    95     96      keywordhash.h
    96     97      mutex.h
    97     98      opcodes.h
    98     99      os_common.h
    99    100      os.h
   100    101      os_os2.h
   101    102      pager.h
................................................................................
   142    143     }
   143    144     set declpattern ^$declpattern
   144    145     while {![eof $in]} {
   145    146       set line [gets $in]
   146    147       if {[regexp {^#\s*include\s+["<]([^">]+)[">]} $line all hdr]} {
   147    148         if {[info exists available_hdr($hdr)]} {
   148    149           if {$available_hdr($hdr)} {
   149         -          if {$hdr!="os_common.h"} {
          150  +          if {$hdr!="os_common.h" && $hdr!="hwtime.h"} {
   150    151               set available_hdr($hdr) 0
   151    152             }
   152    153             section_comment "Include $hdr in the middle of $tail"
   153    154             copy_file tsrc/$hdr
   154    155             section_comment "Continuing where we left off in $tail"
   155    156           }
   156    157         } elseif {![info exists seen_hdr($hdr)]} {
................................................................................
   225    226      os_os2.c
   226    227      os_unix.c
   227    228      os_win.c
   228    229   
   229    230      bitvec.c
   230    231      pager.c
   231    232   
   232         -   btmutex.c   
          233  +   btmutex.c
   233    234      btree.c
   234    235   
   235    236      vdbefifo.c
   236    237      vdbemem.c
   237    238      vdbeaux.c
   238    239      vdbeapi.c
   239    240      vdbe.c

Changes to tool/mksqlite3internalh.tcl.

    52     52   # files are seen in a #include statement in the C code, include the complete
    53     53   # text of the file in-line.  The file only needs to be included once.
    54     54   #
    55     55   foreach hdr {
    56     56      btree.h
    57     57      btreeInt.h
    58     58      hash.h
           59  +   hwtime.h
    59     60      keywordhash.h
    60     61      opcodes.h
    61     62      os_common.h
    62     63      os.h
    63     64      os_os2.h
    64     65      pager.h
    65     66      parse.h

Changes to tool/speedtest16.c.

    11     11   ** will full optimizations.  For example:
    12     12   **
    13     13   **     gcc -c -O6 -DSQLITE_THREADSAFE=0 sqlite3.c
    14     14   **
    15     15   ** Then link against this program.  But to do optimize this program
    16     16   ** because that defeats the hi-res timer.
    17     17   **
    18         -**     gcc speedtest16.c sqlite3.o -ldl
           18  +**     gcc speedtest16.c sqlite3.o -ldl -I../src
    19     19   **
    20     20   ** Then run this program with a single argument which is the name of
    21     21   ** a file containing SQL script that you want to test:
    22     22   **
    23     23   **     ./a.out database.db test.sql
    24     24   */
    25     25   #include <stdio.h>
    26     26   #include <string.h>
    27     27   #include <stdlib.h>
    28     28   #include <ctype.h>
    29     29   #include <unistd.h>
    30     30   #include "sqlite3.h"
    31     31   
    32         -
    33         -/*
    34         -** The following routine only works on pentium-class processors.
    35         -** It uses the RDTSC opcode to read the cycle count value out of the
    36         -** processor and returns that value.  This can be used for high-res
    37         -** profiling.
           32  +/* 
           33  +** hwtime.h contains inline assembler code for implementing 
           34  +** high-performance timing routines.
    38     35   */
    39         -__inline__ unsigned long long int hwtime(void){
    40         -   unsigned int lo, hi;
    41         -   /* We cannot use "=A", since this would use %rax on x86_64 */
    42         -   __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi));
    43         -   return (unsigned long long int)hi << 32 | lo;
    44         -}
           36  +#include "hwtime.h"
    45     37   
    46     38   /*
    47     39   ** Convert a zero-terminated ASCII string into a zero-terminated
    48     40   ** UTF-16le string.  Memory to hold the returned string comes 
    49     41   ** from malloc() and should be freed by the caller.
    50     42   */
    51     43   static void *asciiToUtf16le(const char *z){
................................................................................
    60     52     }
    61     53     return (void*)z16;
    62     54   }
    63     55   
    64     56   /*
    65     57   ** Timers
    66     58   */
    67         -static unsigned long long int prepTime = 0;
    68         -static unsigned long long int runTime = 0;
    69         -static unsigned long long int finalizeTime = 0;
           59  +static sqlite_uint64 prepTime = 0;
           60  +static sqlite_uint64 runTime = 0;
           61  +static sqlite_uint64 finalizeTime = 0;
    70     62   
    71     63   /*
    72     64   ** Prepare and run a single statement of SQL.
    73     65   */
    74     66   static void prepareAndRun(sqlite3 *db, const char *zSql){
    75     67     void *utf16;
    76     68     sqlite3_stmt *pStmt;
    77     69     const void *stmtTail;
    78         -  unsigned long long int iStart, iElapse;
           70  +  sqlite_uint64 iStart, iElapse;
    79     71     int rc;
    80     72     
    81     73     printf("****************************************************************\n");
    82     74     printf("SQL statement: [%s]\n", zSql);
    83     75     utf16 = asciiToUtf16le(zSql);
    84         -  iStart = hwtime();
           76  +  iStart = sqlite3Hwtime();
    85     77     rc = sqlite3_prepare16_v2(db, utf16, -1, &pStmt, &stmtTail);
    86         -  iElapse = hwtime() - iStart;
           78  +  iElapse = sqlite3Hwtime() - iStart;
    87     79     prepTime += iElapse;
    88     80     printf("sqlite3_prepare16_v2() returns %d in %llu cycles\n", rc, iElapse);
    89     81     if( rc==SQLITE_OK ){
    90     82       int nRow = 0;
    91         -    iStart = hwtime();
           83  +    iStart = sqlite3Hwtime();
    92     84       while( (rc=sqlite3_step(pStmt))==SQLITE_ROW ){ nRow++; }
    93         -    iElapse = hwtime() - iStart;
           85  +    iElapse = sqlite3Hwtime() - iStart;
    94     86       runTime += iElapse;
    95     87       printf("sqlite3_step() returns %d after %d rows in %llu cycles\n",
    96     88              rc, nRow, iElapse);
    97         -    iStart = hwtime();
           89  +    iStart = sqlite3Hwtime();
    98     90       rc = sqlite3_finalize(pStmt);
    99         -    iElapse = hwtime() - iStart;
           91  +    iElapse = sqlite3Hwtime() - iStart;
   100     92       finalizeTime += iElapse;
   101     93       printf("sqlite3_finalize() returns %d in %llu cycles\n", rc, iElapse);
   102     94     }
   103     95     free(utf16);
   104     96   }
   105     97   
   106     98   int main(int argc, char **argv){
................................................................................
   107     99     void *utf16;
   108    100     sqlite3 *db;
   109    101     int rc;
   110    102     int nSql;
   111    103     char *zSql;
   112    104     int i, j;
   113    105     FILE *in;
   114         -  unsigned long long int iStart, iElapse;
   115         -  unsigned long long int iSetup = 0;
          106  +  sqlite_uint64 iStart, iElapse;
          107  +  sqlite_uint64 iSetup = 0;
   116    108     int nStmt = 0;
   117    109     int nByte = 0;
   118    110   
   119    111     if( argc!=3 ){
   120    112       fprintf(stderr, "Usage: %s FILENAME SQL-SCRIPT\n"
   121    113                       "Runs SQL-SCRIPT as UTF16 against a UTF16 database\n",
   122    114                       argv[0]);
................................................................................
   129    121     fseek(in, 0L, SEEK_SET);
   130    122     nSql = fread(zSql, 1, nSql, in);
   131    123     zSql[nSql] = 0;
   132    124   
   133    125     printf("SQLite version: %d\n", sqlite3_libversion_number());
   134    126     unlink(argv[1]);
   135    127     utf16 = asciiToUtf16le(argv[1]);
   136         -  iStart = hwtime();
          128  +  iStart = sqlite3Hwtime();
   137    129     rc = sqlite3_open16(utf16, &db);
   138         -  iElapse = hwtime() - iStart;
          130  +  iElapse = sqlite3Hwtime() - iStart;
   139    131     iSetup = iElapse;
   140    132     printf("sqlite3_open16() returns %d in %llu cycles\n", rc, iElapse);
   141    133     free(utf16);
   142    134     for(i=j=0; j<nSql; j++){
   143    135       if( zSql[j]==';' ){
   144    136         int isComplete;
   145    137         char c = zSql[j+1];
................................................................................
   155    147             prepareAndRun(db, &zSql[i]);
   156    148           }
   157    149           zSql[j] = ';';
   158    150           i = j+1;
   159    151         }
   160    152       }
   161    153     }
   162         -  iStart = hwtime();
          154  +  iStart = sqlite3Hwtime();
   163    155     sqlite3_close(db);
   164         -  iElapse = hwtime() - iStart;
          156  +  iElapse = sqlite3Hwtime() - iStart;
   165    157     iSetup += iElapse;
   166    158     printf("sqlite3_close() returns in %llu cycles\n", iElapse);
   167    159     printf("\n");
   168    160     printf("Statements run:       %15d\n", nStmt);
   169    161     printf("Bytes of SQL text:    %15d\n", nByte);
   170    162     printf("Total prepare time:   %15llu cycles\n", prepTime);
   171    163     printf("Total run time:       %15llu cycles\n", runTime);
   172    164     printf("Total finalize time:  %15llu cycles\n", finalizeTime);
   173    165     printf("Open/Close time:      %15llu cycles\n", iSetup);
   174    166     printf("Total Time:           %15llu cycles\n",
   175    167         prepTime + runTime + finalizeTime + iSetup);
   176    168     return 0;
   177    169   }

Changes to tool/speedtest8.c.

    10     10   ** will full optimizations.  For example:
    11     11   **
    12     12   **     gcc -c -O6 -DSQLITE_THREADSAFE=0 sqlite3.c
    13     13   **
    14     14   ** Then link against this program.  But to do optimize this program
    15     15   ** because that defeats the hi-res timer.
    16     16   **
    17         -**     gcc speedtest8.c sqlite3.o -ldl
           17  +**     gcc speedtest8.c sqlite3.o -ldl -I../src
    18     18   **
    19     19   ** Then run this program with a single argument which is the name of
    20     20   ** a file containing SQL script that you want to test:
    21     21   **
    22     22   **     ./a.out test.db  test.sql
    23     23   */
    24     24   #include <stdio.h>
    25     25   #include <string.h>
    26     26   #include <stdlib.h>
    27     27   #include <ctype.h>
           28  +#include <time.h>
           29  +
           30  +#if defined(_MSC_VER)
           31  +#include <windows.h>
           32  +#else
    28     33   #include <unistd.h>
    29     34   #include <sys/times.h>
    30         -#include <time.h>
    31     35   #include <sched.h>
           36  +#endif
    32     37   
    33     38   #include "sqlite3.h"
    34     39   
    35         -/*
    36         -** The following routine only works on pentium-class processors.
    37         -** It uses the RDTSC opcode to read the cycle count value out of the
    38         -** processor and returns that value.  This can be used for high-res
    39         -** profiling.
           40  +/* 
           41  +** hwtime.h contains inline assembler code for implementing 
           42  +** high-performance timing routines.
    40     43   */
    41         -__inline__ unsigned long long int hwtime(void){
    42         -   unsigned int lo, hi;
    43         -   /* We cannot use "=A", since this would use %rax on x86_64 */
    44         -   __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi));
    45         -   return (unsigned long long int)hi << 32 | lo;
    46         -}
           44  +#include "hwtime.h"
    47     45   
    48     46   /*
    49     47   ** Timers
    50     48   */
    51         -static unsigned long long int prepTime = 0;
    52         -static unsigned long long int runTime = 0;
    53         -static unsigned long long int finalizeTime = 0;
           49  +static sqlite_uint64 prepTime = 0;
           50  +static sqlite_uint64 runTime = 0;
           51  +static sqlite_uint64 finalizeTime = 0;
    54     52   
    55     53   /*
    56     54   ** Prepare and run a single statement of SQL.
    57     55   */
    58     56   static void prepareAndRun(sqlite3 *db, const char *zSql, int bQuiet){
    59     57     sqlite3_stmt *pStmt;
    60     58     const char *stmtTail;
    61         -  unsigned long long int iStart, iElapse;
           59  +  sqlite_uint64 iStart, iElapse;
    62     60     int rc;
    63     61     
    64     62     if (!bQuiet){
    65     63       printf("***************************************************************\n");
    66     64     }
    67     65     if (!bQuiet) printf("SQL statement: [%s]\n", zSql);
    68         -  iStart = hwtime();
           66  +  iStart = sqlite3Hwtime();
    69     67     rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, &stmtTail);
    70         -  iElapse = hwtime() - iStart;
           68  +  iElapse = sqlite3Hwtime() - iStart;
    71     69     prepTime += iElapse;
    72     70     if (!bQuiet){
    73     71       printf("sqlite3_prepare_v2() returns %d in %llu cycles\n", rc, iElapse);
    74     72     }
    75     73     if( rc==SQLITE_OK ){
    76     74       int nRow = 0;
    77         -    iStart = hwtime();
           75  +    iStart = sqlite3Hwtime();
    78     76       while( (rc=sqlite3_step(pStmt))==SQLITE_ROW ){ nRow++; }
    79         -    iElapse = hwtime() - iStart;
           77  +    iElapse = sqlite3Hwtime() - iStart;
    80     78       runTime += iElapse;
    81     79       if (!bQuiet){
    82     80         printf("sqlite3_step() returns %d after %d rows in %llu cycles\n",
    83     81                rc, nRow, iElapse);
    84     82       }
    85         -    iStart = hwtime();
           83  +    iStart = sqlite3Hwtime();
    86     84       rc = sqlite3_finalize(pStmt);
    87         -    iElapse = hwtime() - iStart;
           85  +    iElapse = sqlite3Hwtime() - iStart;
    88     86       finalizeTime += iElapse;
    89     87       if (!bQuiet){
    90     88         printf("sqlite3_finalize() returns %d in %llu cycles\n", rc, iElapse);
    91     89       }
    92     90     }
    93     91   }
    94     92   
................................................................................
   178    176   int main(int argc, char **argv){
   179    177     sqlite3 *db;
   180    178     int rc;
   181    179     int nSql;
   182    180     char *zSql;
   183    181     int i, j;
   184    182     FILE *in;
   185         -  unsigned long long int iStart, iElapse;
   186         -  unsigned long long int iSetup = 0;
          183  +  sqlite_uint64 iStart, iElapse;
          184  +  sqlite_uint64 iSetup = 0;
   187    185     int nStmt = 0;
   188    186     int nByte = 0;
   189    187     const char *zArgv0 = argv[0];
   190    188     int bQuiet = 0;
          189  +#if !defined(_MSC_VER)
   191    190     struct tms tmsStart, tmsEnd;
   192    191     clock_t clkStart, clkEnd;
          192  +#endif
   193    193   
   194    194   #ifdef HAVE_OSINST
   195    195     extern sqlite3_vfs *sqlite3_instvfs_binarylog(char *, char *, char *);
   196    196     extern void sqlite3_instvfs_destroy(sqlite3_vfs *);
   197    197     sqlite3_vfs *pVfs = 0;
   198    198   #endif
   199    199   
................................................................................
   219    219       /*
   220    220       ** Increasing the priority slightly above normal can help with
   221    221       ** repeatability of testing.  Note that with Cygwin, -5 equates
   222    222       ** to "High", +5 equates to "Low", and anything in between
   223    223       ** equates to "Normal".
   224    224       */
   225    225       if( argc>4 && (strcmp(argv[1], "-priority")==0) ){
          226  +#if defined(_MSC_VER)
          227  +      int new_priority = atoi(argv[2]);
          228  +      if(!SetPriorityClass(GetCurrentProcess(), 
          229  +        (new_priority<=-5) ? HIGH_PRIORITY_CLASS : 
          230  +        (new_priority<=0)  ? ABOVE_NORMAL_PRIORITY_CLASS : 
          231  +        (new_priority==0)  ? NORMAL_PRIORITY_CLASS : 
          232  +        (new_priority<5)   ? BELOW_NORMAL_PRIORITY_CLASS : 
          233  +        IDLE_PRIORITY_CLASS)){
          234  +        printf ("error setting priority\n"); 
          235  +        exit(2); 
          236  +      }
          237  +#else
   226    238         struct sched_param myParam;
   227    239         sched_getparam(0, &myParam);
   228    240         printf ("Current process priority is %d.\n", (int)myParam.sched_priority); 
   229    241         myParam.sched_priority = atoi(argv[2]);
   230    242         printf ("Setting process priority to %d.\n", (int)myParam.sched_priority); 
   231    243         if (sched_setparam (0, &myParam) != 0){
   232    244           printf ("error setting priority\n"); 
   233    245           exit(2); 
   234    246         }
          247  +#endif
   235    248         argv += 2;
   236    249         argc -= 2;
   237    250         continue;
   238    251       }
   239    252   
   240    253       if( argc>3 && strcmp(argv[1], "-quiet")==0 ){
   241    254        bQuiet = -1;
................................................................................
   267    280     zSql = malloc( nSql+1 );
   268    281     fseek(in, 0L, SEEK_SET);
   269    282     nSql = fread(zSql, 1, nSql, in);
   270    283     zSql[nSql] = 0;
   271    284   
   272    285     printf("SQLite version: %d\n", sqlite3_libversion_number());
   273    286     unlink(argv[1]);
          287  +#if !defined(_MSC_VER)
   274    288     clkStart = times(&tmsStart);
   275         -  iStart = hwtime();
          289  +#endif
          290  +  iStart = sqlite3Hwtime();
   276    291     rc = sqlite3_open(argv[1], &db);
   277         -  iElapse = hwtime() - iStart;
          292  +  iElapse = sqlite3Hwtime() - iStart;
   278    293     iSetup = iElapse;
   279    294     if (!bQuiet) printf("sqlite3_open() returns %d in %llu cycles\n", rc, iElapse);
   280    295     for(i=j=0; j<nSql; j++){
   281    296       if( zSql[j]==';' ){
   282    297         int isComplete;
   283    298         char c = zSql[j+1];
   284    299         zSql[j+1] = 0;
................................................................................
   295    310             prepareAndRun(db, &zSql[i], bQuiet);
   296    311           }
   297    312           zSql[j] = ';';
   298    313           i = j+1;
   299    314         }
   300    315       }
   301    316     }
   302         -  iStart = hwtime();
          317  +  iStart = sqlite3Hwtime();
   303    318     sqlite3_close(db);
   304         -  iElapse = hwtime() - iStart;
          319  +  iElapse = sqlite3Hwtime() - iStart;
          320  +#if !defined(_MSC_VER)
   305    321     clkEnd = times(&tmsEnd);
          322  +#endif
   306    323     iSetup += iElapse;
   307    324     if (!bQuiet) printf("sqlite3_close() returns in %llu cycles\n", iElapse);
   308    325   
   309    326     printf("\n");
   310    327     printf("Statements run:        %15d stmts\n", nStmt);
   311    328     printf("Bytes of SQL text:     %15d bytes\n", nByte);
   312    329     printf("Total prepare time:    %15llu cycles\n", prepTime);
   313    330     printf("Total run time:        %15llu cycles\n", runTime);
   314    331     printf("Total finalize time:   %15llu cycles\n", finalizeTime);
   315    332     printf("Open/Close time:       %15llu cycles\n", iSetup);
   316    333     printf("Total time:            %15llu cycles\n",
   317    334         prepTime + runTime + finalizeTime + iSetup);
   318    335   
          336  +#if !defined(_MSC_VER)
   319    337     printf("\n");
   320    338     printf("Total user CPU time:   %15.3g secs\n", (tmsEnd.tms_utime - tmsStart.tms_utime)/(double)CLOCKS_PER_SEC );
   321    339     printf("Total system CPU time: %15.3g secs\n", (tmsEnd.tms_stime - tmsStart.tms_stime)/(double)CLOCKS_PER_SEC );
   322    340     printf("Total real time:       %15.3g secs\n", (clkEnd -clkStart)/(double)CLOCKS_PER_SEC );
          341  +#endif
   323    342   
   324    343   #ifdef HAVE_OSINST
   325    344     if( pVfs ){
   326    345       sqlite3_instvfs_destroy(pVfs);
   327    346       printf("vfs log written to %s\n", argv[0]);
   328    347     }
   329    348   #endif
   330    349   
   331    350     return 0;
   332    351   }

Changes to tool/speedtest8inst1.c.

    10     10   ** will full optimizations.  For example:
    11     11   **
    12     12   **     gcc -c -O6 -DSQLITE_THREADSAFE=0 sqlite3.c
    13     13   **
    14     14   ** Then link against this program.  But to do optimize this program
    15     15   ** because that defeats the hi-res timer.
    16     16   **
    17         -**     gcc speedtest8.c sqlite3.o -ldl
           17  +**     gcc speedtest8.c sqlite3.o -ldl -I../src
    18     18   **
    19     19   ** Then run this program with a single argument which is the name of
    20     20   ** a file containing SQL script that you want to test:
    21     21   **
    22     22   **     ./a.out test.db  test.sql
    23     23   */
    24     24   #include <stdio.h>
................................................................................
    25     25   #include <string.h>
    26     26   #include <stdlib.h>
    27     27   #include <ctype.h>
    28     28   #include <unistd.h>
    29     29   #include <stdarg.h>
    30     30   #include "sqlite3.h"
    31     31   
    32         -/*
    33         -** The following routine only works on pentium-class processors.
    34         -** It uses the RDTSC opcode to read the cycle count value out of the
    35         -** processor and returns that value.  This can be used for high-res
    36         -** profiling.
           32  +/* 
           33  +** hwtime.h contains inline assembler code for implementing 
           34  +** high-performance timing routines.
    37     35   */
    38         -__inline__ sqlite3_uint64 hwtime(void){
    39         -   unsigned int lo, hi;
    40         -   /* We cannot use "=A", since this would use %rax on x86_64 */
    41         -   __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi));
    42         -   return (sqlite3_uint64)hi << 32 | lo;
    43         -}
           36  +#include "hwtime.h"
    44     37   
    45     38   /*
    46     39   ** Send a message to the log file.
    47     40   */
    48     41   static void logMessage(const char *zFormat, ...){
    49     42     va_list ap;
    50     43     va_start(ap, zFormat);
................................................................................
   132    125     instCheckReservedLock,          /* xCheckReservedLock */
   133    126     instFileControl,                /* xFileControl */
   134    127     instSectorSize,                 /* xSectorSize */
   135    128     instDeviceCharacteristics       /* xDeviceCharacteristics */
   136    129   };
   137    130   
   138    131   #define OS_TIME_IO(MESSAGE, A, B, CALL)      \
   139         -  int rc; sqlite3_uint64 t1, t2;             \
          132  +  int rc;                                    \
          133  +  sqlite_uint64 t1, t2;                      \
   140    134     inst_file *p = (inst_file*)pFile;          \
   141         -  t1 = hwtime();                             \
          135  +  t1 = sqlite3Hwtime();                      \
   142    136     rc = CALL;                                 \
   143         -  t2 = hwtime();                             \
          137  +  t2 = sqlite3Hwtime();                      \
   144    138     logMessage(MESSAGE, A, B, t2-t1);          \
   145         -  instTime += hwtime() - t2;                 \
          139  +  instTime += sqlite3Hwtime() - t2;          \
   146    140     return rc;
   147    141   
   148    142   #define OS_TIME_VFS(MESSAGE, A, B, CALL)                 \
   149    143     int rc;                                                \
   150         -  sqlite3_uint64 t1, t2;                                 \
          144  +  sqlite_uint64 t1, t2;                                  \
   151    145     sqlite3_vfs *pRealVfs = (sqlite3_vfs*)pVfs->pAppData;  \
   152         -  t1 = hwtime();                                         \
          146  +  t1 = sqlite3Hwtime();                                  \
   153    147     rc = CALL;                                             \
   154         -  t2 = hwtime();                                         \
          148  +  t2 = sqlite3Hwtime();                                  \
   155    149     logMessage(MESSAGE, A, B, t2-t1);                      \
   156         -  instTime += hwtime() - t2;                             \
          150  +  instTime += sqlite3Hwtime() - t2;                      \
   157    151     return rc;
   158    152   
   159    153   
   160    154   /*
   161    155   ** Close an inst-file.
   162    156   */
   163    157   static int instClose(sqlite3_file *pFile){
................................................................................
   433    427   
   434    428   /*
   435    429   ** Prepare and run a single statement of SQL.
   436    430   */
   437    431   static void prepareAndRun(sqlite3 *db, const char *zSql){
   438    432     sqlite3_stmt *pStmt;
   439    433     const char *stmtTail;
   440         -  sqlite3_uint64 iStart, iElapse;
          434  +  sqlite_uint64 iStart, iElapse;
   441    435     int rc;
   442    436     
   443    437     printf("****************************************************************\n");
   444    438     printf("SQL statement: [%s]\n", zSql);
   445    439     instTime = 0;
   446         -  iStart = hwtime();
          440  +  iStart = sqlite3Hwtime();
   447    441     rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, &stmtTail);
   448         -  iElapse = hwtime();
          442  +  iElapse = sqlite3Hwtime();
   449    443     iElapse -= iStart + instTime;
   450    444     prepTime += iElapse;
   451    445     printf("sqlite3_prepare_v2() returns %d in %llu cycles\n", rc, iElapse);
   452    446     if( rc==SQLITE_OK ){
   453    447       int nRow = 0;
   454    448       instTime = 0;
   455         -    iStart = hwtime();
          449  +    iStart = sqlite3Hwtime();
   456    450       while( (rc=sqlite3_step(pStmt))==SQLITE_ROW ){ nRow++; }
   457         -    iElapse = hwtime();
          451  +    iElapse = sqlite3Hwtime();
   458    452       iElapse -= iStart + instTime;
   459    453       runTime += iElapse;
   460    454       printf("sqlite3_step() returns %d after %d rows in %llu cycles\n",
   461    455              rc, nRow, iElapse);
   462    456       instTime = 0;
   463         -    iStart = hwtime();
          457  +    iStart = sqlite3Hwtime();
   464    458       rc = sqlite3_finalize(pStmt);
   465         -    iElapse = hwtime();
          459  +    iElapse = sqlite3Hwtime();
   466    460       iElapse -= iStart + instTime;
   467    461       finalizeTime += iElapse;
   468    462       printf("sqlite3_finalize() returns %d in %llu cycles\n", rc, iElapse);
   469    463     }
   470    464   }
   471    465   
   472    466   int main(int argc, char **argv){
   473    467     sqlite3 *db;
   474    468     int rc;
   475    469     int nSql;
   476    470     char *zSql;
   477    471     int i, j;
   478    472     FILE *in;
   479         -  sqlite3_uint64 iStart, iElapse;
   480         -  sqlite3_uint64 iSetup = 0;
          473  +  sqlite_uint64 iStart, iElapse;
          474  +  sqlite_uint64 iSetup = 0;
   481    475     int nStmt = 0;
   482    476     int nByte = 0;
   483    477   
   484    478     if( argc!=3 ){
   485    479       fprintf(stderr, "Usage: %s FILENAME SQL-SCRIPT\n"
   486    480                       "Runs SQL-SCRIPT against a UTF8 database\n",
   487    481                       argv[0]);
................................................................................
   495    489     nSql = fread(zSql, 1, nSql, in);
   496    490     zSql[nSql] = 0;
   497    491   
   498    492     printf("SQLite version: %d\n", sqlite3_libversion_number());
   499    493     unlink(argv[1]);
   500    494     setupInstrumentedVfs();
   501    495     instTime = 0;
   502         -  iStart = hwtime();
          496  +  iStart = sqlite3Hwtime();
   503    497     rc = sqlite3_open(argv[1], &db);
   504         -  iElapse = hwtime();
          498  +  iElapse = sqlite3Hwtime();
   505    499     iElapse -= iStart + instTime;
   506    500     iSetup = iElapse;
   507    501     printf("sqlite3_open() returns %d in %llu cycles\n", rc, iElapse);
   508    502     for(i=j=0; j<nSql; j++){
   509    503       if( zSql[j]==';' ){
   510    504         int isComplete;
   511    505         char c = zSql[j+1];
................................................................................
   522    516           }
   523    517           zSql[j] = ';';
   524    518           i = j+1;
   525    519         }
   526    520       }
   527    521     }
   528    522     instTime = 0;
   529         -  iStart = hwtime();
          523  +  iStart = sqlite3Hwtime();
   530    524     sqlite3_close(db);
   531         -  iElapse = hwtime();
          525  +  iElapse = sqlite3Hwtime();
   532    526     iElapse -= iStart + instTime;
   533    527     iSetup += iElapse;
   534    528     printf("sqlite3_close() returns in %llu cycles\n", iElapse);
   535    529     printf("\n");
   536    530     printf("Statements run:       %15d\n", nStmt);
   537    531     printf("Bytes of SQL text:    %15d\n", nByte);
   538    532     printf("Total prepare time:   %15llu cycles\n", prepTime);