/ Check-in [e1322415]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

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

Overview
Comment:Add the --ostrace and --ossummary options to tester.tcl. To log calls the vfs layer from within test scripts. (CVS 4984)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: e1322415d0ca2d6b45f35ef9257b37161ec043e2
User & Date: danielk1977 2008-04-10 17:27:39
Context
2008-04-10
18:35
Correctly handle virtual tables that are created and dropped all within a single transaction. Ticket #2994. (CVS 4985) check-in: 0acb1b42 user: drh tags: trunk
17:27
Add the --ostrace and --ossummary options to tester.tcl. To log calls the vfs layer from within test scripts. (CVS 4984) check-in: e1322415 user: danielk1977 tags: trunk
17:14
Enhanced testing and documentation of sqlite3_result_error_code(). Ticket #2940. (CVS 4983) check-in: 5be56dbe user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/test_osinst.c.

   211    211   
   212    212   /*
   213    213   ** The following routine only works on pentium-class processors.
   214    214   ** It uses the RDTSC opcode to read the cycle count value out of the
   215    215   ** processor and returns that value.  This can be used for high-res
   216    216   ** profiling.
   217    217   */
          218  +#if defined(i386) || defined(__i386__) || defined(_M_IX86)
   218    219   __inline__ unsigned long long int hwtime(void){
   219    220     unsigned long long int x;
   220    221     __asm__("rdtsc\n\t"
   221    222             "mov %%edx, %%ecx\n\t"
   222    223             :"=A" (x));
   223    224     return x;
   224    225   }
          226  +#else
          227  +  static unsigned long long int hwtime(void){ return 0; }
          228  +#endif
   225    229   
   226    230   #define OS_TIME_IO(eEvent, A, B, Call) {     \
   227    231     inst_file *p = (inst_file *)pFile;         \
   228    232     InstVfs *pInstVfs = p->pInstVfs;           \
   229    233     int rc;                                    \
   230    234     i64 t = hwtime();                          \
   231    235     rc = Call;                                 \
................................................................................
   514    518     p->xCall = xCall;
   515    519     p->xDel = xDel;
   516    520     p->pClient = pClient;
   517    521   }
   518    522   
   519    523   void sqlite3_instvfs_destroy(sqlite3_vfs *pVfs){
   520    524     sqlite3_vfs_unregister(pVfs);
          525  +  sqlite3_instvfs_configure(pVfs, 0, 0, 0);
   521    526     sqlite3_free(pVfs);
   522    527   }
   523    528   
   524    529   void sqlite3_instvfs_reset(sqlite3_vfs *pVfs){
   525    530     InstVfs *p = (InstVfs *)pVfs;
   526    531     assert( pVfs->xOpen==instOpen );
   527    532     memset(p->aTime, 0, sizeof(i64)*OS_NUMEVENTS);
................................................................................
   642    647       return TCL_ERROR;
   643    648     }
   644    649   
   645    650     switch( (enum IV_enum)iSub ){
   646    651       case IV_CREATE: {
   647    652         char *zParent = 0;
   648    653         sqlite3_vfs *p;
   649         -      if( objc!=4 && objc!=3 ){
   650         -        Tcl_WrongNumArgs(interp, 2, objv, "NAME ?PARENT-VFS?");
          654  +      int isDefault = 0;
          655  +      if( objc>2 && 0==strcmp("-default", Tcl_GetString(objv[2])) ){
          656  +        isDefault = 1;
          657  +      }
          658  +      if( (objc-isDefault)!=4 && (objc-isDefault)!=3 ){
          659  +        Tcl_WrongNumArgs(interp, 2, objv, "?-default? NAME ?PARENT-VFS?");
   651    660           return TCL_ERROR;
   652    661         }
   653         -      if( objc==4 ){
   654         -        zParent = Tcl_GetString(objv[3]);
          662  +      if( objc==(4+isDefault) ){
          663  +        zParent = Tcl_GetString(objv[3+isDefault]);
   655    664         }
   656         -      p = sqlite3_instvfs_create(Tcl_GetString(objv[2]), zParent);
          665  +      p = sqlite3_instvfs_create(Tcl_GetString(objv[2+isDefault]), zParent);
   657    666         if( !p ){
   658    667           Tcl_AppendResult(interp, "error creating vfs ", 0);
   659    668           return TCL_ERROR;
   660    669         }
          670  +      if( isDefault ){
          671  +        sqlite3_vfs_register(p, 1);
          672  +      }
   661    673         Tcl_SetObjResult(interp, objv[2]);
   662    674         break;
   663    675       }
   664    676   
   665    677       case IV_CONFIGURE: {
   666    678         InstVfsCall *pCall;
   667    679   

Changes to test/tester.tcl.

     7      7   #    May you find forgiveness for yourself and forgive others.
     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements some common TCL routines used for regression
    12     12   # testing the SQLite library
    13     13   #
    14         -# $Id: tester.tcl,v 1.113 2008/03/29 11:00:55 drh Exp $
           14  +# $Id: tester.tcl,v 1.114 2008/04/10 17:27:39 danielk1977 Exp $
    15     15   
    16     16   #
    17     17   # What for user input before continuing.  This gives an opportunity
    18     18   # to connect profiling tools to the process.
    19     19   #
    20     20   for {set i 0} {$i<[llength $argv]} {incr i} {
    21     21     if {[regexp {^-+pause$} [lindex $argv $i] all value]} {
................................................................................
    57     57   # test_malloc.c for additional information.
    58     58   #
    59     59   for {set i 0} {$i<[llength $argv]} {incr i} {
    60     60     if {[lindex $argv $i] eq "--malloctrace"} {
    61     61       set argv [lreplace $argv $i $i]
    62     62       sqlite3_memdebug_backtrace 10
    63     63       sqlite3_memdebug_log start
    64         -    set argv [lreplace $argv $i $i]
    65     64       set tester_do_malloctrace 1
    66     65     }
    67     66   }
    68     67   for {set i 0} {$i<[llength $argv]} {incr i} {
    69     68     if {[regexp {^--backtrace=(\d+)$} [lindex $argv $i] all value]} {
    70     69       sqlite3_memdebug_backtrace $value
    71     70       set argv [lreplace $argv $i $i]
    72     71     }
    73     72   }
    74     73   
           74  +
           75  +proc ostrace_call {zCall nClick zFile i32 i64} {
           76  +  set s "INSERT INTO ostrace VALUES( '$zCall', $nClick, '$zFile', $i32, $i64);"
           77  +  puts $::ostrace_fd $s
           78  +}
           79  +
           80  +for {set i 0} {$i<[llength $argv]} {incr i} {
           81  +  if {[lindex $argv $i] eq "--ossummary" || [lindex $argv $i] eq "--ostrace"} {
           82  +    sqlite3_instvfs create -default ostrace
           83  +    set tester_do_ostrace 1
           84  +    set ostrace_fd [open ostrace.sql w]
           85  +    puts $ostrace_fd "BEGIN;"
           86  +    if {[lindex $argv $i] eq "--ostrace"} {
           87  +      set    s "CREATE TABLE ostrace"
           88  +      append s "(method TEXT, clicks INT, file TEXT, i32 INT, i64 INT);"
           89  +      puts $ostrace_fd $s
           90  +      sqlite3_instvfs configure ostrace ostrace_call
           91  +    }
           92  +    set argv [lreplace $argv $i $i]
           93  +  }
           94  +}
           95  +
    75     96   # 
    76     97   # Check the command-line arguments to set the maximum number of
    77     98   # errors tolerated before halting.
    78     99   #
    79    100   if {![info exists maxErr]} {
    80    101     set maxErr 1000
    81    102   }
................................................................................
   244    265       puts "all of the test failures above might be a result from this defect"
   245    266       puts "in your TCL build."
   246    267       puts "******************************************************************"
   247    268     }
   248    269     if {$sqlite_open_file_count} {
   249    270       puts "$sqlite_open_file_count files were left open"
   250    271       incr nErr
          272  +  }
          273  +  if {[info exists ::tester_do_ostrace]} {
          274  +    puts "Writing ostrace.sql..."
          275  +    set fd $::ostrace_fd
          276  +
          277  +    puts -nonewline $fd "CREATE TABLE ossummary"
          278  +    puts $fd "(method TEXT, clicks INTEGER, count INTEGER);"
          279  +    foreach row [sqlite3_instvfs report ostrace] {
          280  +      foreach {method count clicks} $row break
          281  +      puts $fd "INSERT INTO ossummary VALUES('$method', $clicks, $count);"
          282  +    }
          283  +    puts $fd "COMMIT;"
          284  +    close $fd
          285  +    sqlite3_instvfs destroy ostrace
   251    286     }
   252    287     if {[sqlite3_memory_used]>0} {
   253    288       puts "Unfreed memory: [sqlite3_memory_used] bytes"
   254    289       incr nErr
   255    290       ifcapable memdebug||mem5||(mem3&&debug) {
   256    291         puts "Writing unfreed memory log to \"./memleak.txt\""
   257    292         sqlite3_memdebug_dump ./memleak.txt