/ Check-in [e327ef37]
Login

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

Overview
Comment:When calculating schema memory, use the actual allocated size of hash elements, not sizeof(HashElem). Also fix a bug in dbstatus.test.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | experimental
Files: files | file ages | folders
SHA1: e327ef37faec52ce99591266160be2ce2d577cc3
User & Date: dan 2010-07-26 15:57:02
Original Comment: When calculating schema memory, use the actual allocated size of hash elements, not sizeof(HashElem). Also fix a bug in dbstatus.test
Context
2010-07-26
16:24
Add support for SQLITE_DBSTATUS_SCHEMA_USED and SQLITE_DBSTATUS_STMT_USED to the trunk. check-in: 008368b2 user: drh tags: trunk
15:57
When calculating schema memory, use the actual allocated size of hash elements, not sizeof(HashElem). Also fix a bug in dbstatus.test. Closed-Leaf check-in: e327ef37 user: dan tags: experimental
14:47
Add virtual table test cases to dbstatus.test. check-in: 72b84d06 user: dan tags: experimental
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/status.c.

   145    145       */
   146    146       case SQLITE_DBSTATUS_SCHEMA_USED: {
   147    147         int i;                      /* Used to iterate through schemas */
   148    148         int nByte = 0;              /* Used to accumulate return value */
   149    149   
   150    150         db->pnBytesFreed = &nByte;
   151    151         for(i=0; i<db->nDb; i++){
   152         -	Schema *pSchema = db->aDb[i].pSchema;
   153         -	if( pSchema ){
   154         -  	  HashElem *p;
          152  +        Schema *pSchema = db->aDb[i].pSchema;
          153  +        if( pSchema ){
          154  +            HashElem *p;
   155    155   
   156         -	  nByte += sizeof(HashElem) * (
   157         -	      pSchema->tblHash.count 
   158         -	    + pSchema->trigHash.count
   159         -	    + pSchema->idxHash.count
   160         -	    + pSchema->fkeyHash.count
   161         -	  );
   162         -	  nByte += sqlite3MallocSize(pSchema->tblHash.ht);
   163         -	  nByte += sqlite3MallocSize(pSchema->trigHash.ht);
   164         -	  nByte += sqlite3MallocSize(pSchema->idxHash.ht);
   165         -	  nByte += sqlite3MallocSize(pSchema->fkeyHash.ht);
          156  +          nByte += sqlite3GlobalConfig.m.xRoundup(sizeof(HashElem)) * (
          157  +              pSchema->tblHash.count 
          158  +            + pSchema->trigHash.count
          159  +            + pSchema->idxHash.count
          160  +            + pSchema->fkeyHash.count
          161  +          );
          162  +          nByte += sqlite3MallocSize(pSchema->tblHash.ht);
          163  +          nByte += sqlite3MallocSize(pSchema->trigHash.ht);
          164  +          nByte += sqlite3MallocSize(pSchema->idxHash.ht);
          165  +          nByte += sqlite3MallocSize(pSchema->fkeyHash.ht);
   166    166   
   167    167             for(p=sqliteHashFirst(&pSchema->trigHash); p; p=sqliteHashNext(p)){
   168    168               sqlite3DeleteTrigger(db, (Trigger*)sqliteHashData(p));
   169    169             }
   170    170             for(p=sqliteHashFirst(&pSchema->tblHash); p; p=sqliteHashNext(p)){
   171    171               sqlite3DeleteTable(db, (Table *)sqliteHashData(p));
   172    172             }
   173         -	}
          173  +        }
   174    174         }
   175    175         db->pnBytesFreed = 0;
   176    176   
   177    177         *pHighwater = 0;
   178    178         *pCurrent = nByte;
   179    179         break;
   180    180       }
................................................................................
   186    186       */
   187    187       case SQLITE_DBSTATUS_STMT_USED: {
   188    188         struct Vdbe *pVdbe;         /* Used to iterate through VMs */
   189    189         int nByte = 0;              /* Used to accumulate return value */
   190    190   
   191    191         db->pnBytesFreed = &nByte;
   192    192         for(pVdbe=db->pVdbe; pVdbe; pVdbe=pVdbe->pNext){
   193         -	sqlite3VdbeDeleteObject(db, pVdbe);
          193  +        sqlite3VdbeDeleteObject(db, pVdbe);
   194    194         }
   195    195         db->pnBytesFreed = 0;
   196    196   
   197    197         *pHighwater = 0;
   198    198         *pCurrent = nByte;
   199    199   
   200    200         break;

Changes to test/dbstatus.test.

   287    287       incr nAlloc1 [lookaside db]
   288    288       set nStmt1   [lindex [sqlite3_db_status db SQLITE_DBSTATUS_STMT_USED 0] 1]
   289    289       execsql $statements
   290    290     
   291    291       # Step 3.
   292    292       db cache flush
   293    293       set nAlloc2  [lindex [sqlite3_status SQLITE_STATUS_MEMORY_USED 0] 1]
   294         -    incr nAlloc3 [lookaside db]
          294  +    incr nAlloc2 [lookaside db]
   295    295       set nStmt2   [lindex [sqlite3_db_status db SQLITE_DBSTATUS_STMT_USED 0] 1]
   296    296       
   297    297       # Step 3.
   298    298       execsql $statements
   299    299       set nAlloc3  [lindex [sqlite3_status SQLITE_STATUS_MEMORY_USED 0] 1]
   300    300       incr nAlloc3 [lookaside db]
   301    301       set nStmt3   [lindex [sqlite3_db_status db SQLITE_DBSTATUS_STMT_USED 0] 1]