/ Check-in [908e2c21]
Login

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

Overview
Comment:Enhance the timer in the shell to show wall-clock time in addition to user and kernel CPU time.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 908e2c2124baece578e7a665f42b6b483b8f1d64
User & Date: drh 2013-10-30 12:43:36
Context
2013-10-31
06:11
Fix harmless compiler warnings. check-in: 1a0a8865 user: mistachkin tags: trunk
2013-10-30
12:43
Enhance the timer in the shell to show wall-clock time in addition to user and kernel CPU time. check-in: 908e2c21 user: drh tags: trunk
03:25
Add the "Esri Spatially-Enabled Database" file format to the magic.txt file. check-in: 8530a18f user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/shell.c.

    82     82   /* Windows CE (arm-wince-mingw32ce-gcc) does not provide isatty()
    83     83    * thus we always assume that we have a console. That can be
    84     84    * overridden with the -batch command line option.
    85     85    */
    86     86   #define isatty(x) 1
    87     87   #endif
    88     88   
    89         -/* True if the timer is enabled */
    90         -static int enableTimer = 0;
    91         -
    92     89   /* ctype macros that work with signed characters */
    93     90   #define IsSpace(X)  isspace((unsigned char)X)
    94     91   #define IsDigit(X)  isdigit((unsigned char)X)
    95     92   #define ToLower(X)  (char)tolower((unsigned char)X)
    96     93   
           94  +
           95  +/* True if the timer is enabled */
           96  +static int enableTimer = 0;
           97  +
           98  +/* Return the current wall-clock time */
           99  +static sqlite3_int64 timeOfDay(void){
          100  +  static sqlite3_vfs *clockVfs = 0;
          101  +  sqlite3_int64 t;
          102  +  if( clockVfs==0 ) clockVfs = sqlite3_vfs_find(0);
          103  +  if( clockVfs->iVersion>=1 && clockVfs->xCurrentTimeInt64!=0 ){
          104  +    clockVfs->xCurrentTimeInt64(clockVfs, &t);
          105  +  }else{
          106  +    double r;
          107  +    clockVfs->xCurrentTime(clockVfs, &r);
          108  +    t = (sqlite3_int64)(r*86400000.0);
          109  +  }
          110  +  return t;
          111  +}
          112  +
    97    113   #if !defined(_WIN32) && !defined(WIN32) && !defined(_WRS_KERNEL) \
    98    114    && !defined(__minux)
    99    115   #include <sys/time.h>
   100    116   #include <sys/resource.h>
   101    117   
   102    118   /* Saved resource information for the beginning of an operation */
   103         -static struct rusage sBegin;
          119  +static struct rusage sBegin;  /* CPU time at start */
          120  +static sqlite3_int64 iBegin;  /* Wall-clock time at start */
   104    121   
   105    122   /*
   106    123   ** Begin timing an operation
   107    124   */
   108    125   static void beginTimer(void){
   109    126     if( enableTimer ){
   110    127       getrusage(RUSAGE_SELF, &sBegin);
          128  +    iBegin = timeOfDay();
   111    129     }
   112    130   }
   113    131   
   114    132   /* Return the difference of two time_structs in seconds */
   115    133   static double timeDiff(struct timeval *pStart, struct timeval *pEnd){
   116    134     return (pEnd->tv_usec - pStart->tv_usec)*0.000001 + 
   117    135            (double)(pEnd->tv_sec - pStart->tv_sec);
................................................................................
   119    137   
   120    138   /*
   121    139   ** Print the timing results.
   122    140   */
   123    141   static void endTimer(void){
   124    142     if( enableTimer ){
   125    143       struct rusage sEnd;
          144  +    sqlite3_int64 iEnd = timeOfDay();
   126    145       getrusage(RUSAGE_SELF, &sEnd);
   127         -    printf("CPU Time: user %f sys %f\n",
          146  +    printf("Run Time: real %.3f user %f sys %f\n",
          147  +       (iEnd - iBegin)*0.001,
   128    148          timeDiff(&sBegin.ru_utime, &sEnd.ru_utime),
   129    149          timeDiff(&sBegin.ru_stime, &sEnd.ru_stime));
   130    150     }
   131    151   }
   132    152   
   133    153   #define BEGIN_TIMER beginTimer()
   134    154   #define END_TIMER endTimer()
................................................................................
   138    158   
   139    159   #include <windows.h>
   140    160   
   141    161   /* Saved resource information for the beginning of an operation */
   142    162   static HANDLE hProcess;
   143    163   static FILETIME ftKernelBegin;
   144    164   static FILETIME ftUserBegin;
          165  +static sqlite3_int64 ftWallBegin;
   145    166   typedef BOOL (WINAPI *GETPROCTIMES)(HANDLE, LPFILETIME, LPFILETIME, LPFILETIME, LPFILETIME);
   146    167   static GETPROCTIMES getProcessTimesAddr = NULL;
   147    168   
   148    169   /*
   149    170   ** Check to see if we have timer support.  Return 1 if necessary
   150    171   ** support found (or found previously).
   151    172   */
................................................................................
   175    196   /*
   176    197   ** Begin timing an operation
   177    198   */
   178    199   static void beginTimer(void){
   179    200     if( enableTimer && getProcessTimesAddr ){
   180    201       FILETIME ftCreation, ftExit;
   181    202       getProcessTimesAddr(hProcess, &ftCreation, &ftExit, &ftKernelBegin, &ftUserBegin);
          203  +    ftWallBegin = timeOfDay();
   182    204     }
   183    205   }
   184    206   
   185    207   /* Return the difference of two FILETIME structs in seconds */
   186    208   static double timeDiff(FILETIME *pStart, FILETIME *pEnd){
   187    209     sqlite_int64 i64Start = *((sqlite_int64 *) pStart);
   188    210     sqlite_int64 i64End = *((sqlite_int64 *) pEnd);
................................................................................
   191    213   
   192    214   /*
   193    215   ** Print the timing results.
   194    216   */
   195    217   static void endTimer(void){
   196    218     if( enableTimer && getProcessTimesAddr){
   197    219       FILETIME ftCreation, ftExit, ftKernelEnd, ftUserEnd;
          220  +    sqlite3_int64 ftWallEnd = timeOfDay();
   198    221       getProcessTimesAddr(hProcess, &ftCreation, &ftExit, &ftKernelEnd, &ftUserEnd);
   199         -    printf("CPU Time: user %f sys %f\n",
          222  +    printf("Run Time: real %.3f user %f sys %f\n",
          223  +       (ftWallEnd - ftWallBegin)*0.001,
   200    224          timeDiff(&ftUserBegin, &ftUserEnd),
   201    225          timeDiff(&ftKernelBegin, &ftKernelEnd));
   202    226     }
   203    227   }
   204    228   
   205    229   #define BEGIN_TIMER beginTimer()
   206    230   #define END_TIMER endTimer()