/ Check-in [9cd27350]
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 initial ZIPVFS support for the "main" database to the sqlite_memstat virtual table.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | memstat-vtab
Files: files | file ages | folders
SHA3-256: 9cd27350b0f62debfe3238c57c3ab51079699142e82c05a7ec8460a8429f55f2
User & Date: drh 2018-09-27 15:45:03
Context
2018-09-27
16:57
Enhancements to sqlite_memstat: (1) Add an extra "schema" column to show the schema name for ZIPVFS stats. (2) Only show ZIPVFS stats to schema that use ZIPVFS (3) Put a NULL in unused columns of the output. Closed-Leaf check-in: 9351135b user: drh tags: memstat-vtab
15:45
Add initial ZIPVFS support for the "main" database to the sqlite_memstat virtual table. check-in: 9cd27350 user: drh tags: memstat-vtab
15:21
Initial prototype of a eponymous virtual table that accesses sqlite3_status64() and sqlite3_db_status(). check-in: 0b44e1f6 user: drh tags: memstat-vtab
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to ext/misc/memstat.c.

122
123
124
125
126
127
128

129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158








159
160
161
162
163
164
165
...
196
197
198
199
200
201
202




203
204
205
206
207
208
209
...
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232


/*
** Allowed values for aMemstatColumn[].eType
*/
#define MSV_GSTAT   0          /* sqlite3_status64() information */
#define MSV_DBSTAT  1          /* sqlite3_db_status() information */


/*
** An array of quantities that can be measured and reported by
** this virtual table
*/
static const struct MemstatColumns {
  const char *zName;    /* Symbolic name */
  int eType;            /* Type of interface */
  int eOp;              /* Opcode */
} aMemstatColumn[] = {
  { "MEMORY_USED",         MSV_GSTAT,   SQLITE_STATUS_MEMORY_USED          },
  { "MALLOC_SIZE",         MSV_GSTAT,   SQLITE_STATUS_MALLOC_SIZE          },
  { "MALLOC_COUNT",        MSV_GSTAT,   SQLITE_STATUS_MALLOC_COUNT         },
  { "PAGECACHE_USED",      MSV_GSTAT,   SQLITE_STATUS_PAGECACHE_USED       },
  { "PAGECACHE_OVERFLOW",  MSV_GSTAT,   SQLITE_STATUS_PAGECACHE_OVERFLOW   },
  { "PAGECACHE_SIZE",      MSV_GSTAT,   SQLITE_STATUS_PAGECACHE_SIZE       },
  { "PARSER_STACK",        MSV_GSTAT,   SQLITE_STATUS_PARSER_STACK         },
  { "LOOKASIDE_USED",      MSV_DBSTAT, SQLITE_DBSTATUS_LOOKASIDE_USED      },
  { "CACHE_USED",          MSV_DBSTAT, SQLITE_DBSTATUS_CACHE_USED          },
  { "SCHEMA_USED",         MSV_DBSTAT, SQLITE_DBSTATUS_SCHEMA_USED         },
  { "STMT_USED",           MSV_DBSTAT, SQLITE_DBSTATUS_STMT_USED           },
  { "LOOKASIDE_HIT",       MSV_DBSTAT, SQLITE_DBSTATUS_LOOKASIDE_HIT       },
  { "LOOKASIDE_MISS_SIZE", MSV_DBSTAT, SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE },
  { "LOOKASIDE_MISS_FULL", MSV_DBSTAT, SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL },
  { "CACHE_HIT",           MSV_DBSTAT, SQLITE_DBSTATUS_CACHE_HIT           },
  { "CACHE_MISS",          MSV_DBSTAT, SQLITE_DBSTATUS_CACHE_MISS          },
  { "CACHE_WRITE",         MSV_DBSTAT, SQLITE_DBSTATUS_CACHE_WRITE         },
  { "DEFERRED_FKS",        MSV_DBSTAT, SQLITE_DBSTATUS_DEFERRED_FKS        },
  { "CACHE_USED_SHARED",   MSV_DBSTAT, SQLITE_DBSTATUS_CACHE_USED_SHARED   },
  { "CACHE_SPILL",         MSV_DBSTAT, SQLITE_DBSTATUS_CACHE_SPILL         },








};
#define MSV_NROW (sizeof(aMemstatColumn)/sizeof(aMemstatColumn[0]))

/*
** Advance a memstat_cursor to its next row of output.
*/
static int memstatNext(sqlite3_vtab_cursor *cur){
................................................................................
    case MSV_DBSTAT: {
      int xCur, xHiwtr;
      sqlite3_db_status(pCur->db, aMemstatColumn[i].eOp, &xCur, &xHiwtr, 0);
      iCur = xCur;
      iHiwtr = xHiwtr;
      break;
    }




  }
  if( iCol==MSV_COLUMN_HIWTR ) iCur = iHiwtr;
  sqlite3_result_int64(ctx, iCur);
  return SQLITE_OK;
}

/*
................................................................................

/*
** Return TRUE if the cursor has been moved off of the last
** row of output.
*/
static int memstatEof(sqlite3_vtab_cursor *cur){
  memstat_cursor *pCur = (memstat_cursor*)cur;
  return pCur->iRowid>=MSV_NROW;
}

/*
** This method is called to "rewind" the memstat_cursor object back
** to the first row of output.  This method is always called at least
** once prior to any call to memstatColumn() or memstatRowid() or 
** memstatEof().







>










|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>
>
>
>
>
>
>
>







 







>
>
>
>







 







|







122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
...
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
...
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245


/*
** Allowed values for aMemstatColumn[].eType
*/
#define MSV_GSTAT   0          /* sqlite3_status64() information */
#define MSV_DBSTAT  1          /* sqlite3_db_status() information */
#define MSV_ZIPVFS  2          /* ZIPVFS file-control with 64-bit return */

/*
** An array of quantities that can be measured and reported by
** this virtual table
*/
static const struct MemstatColumns {
  const char *zName;    /* Symbolic name */
  int eType;            /* Type of interface */
  int eOp;              /* Opcode */
} aMemstatColumn[] = {
  { "MEMORY_USED",            MSV_GSTAT,   SQLITE_STATUS_MEMORY_USED          },
  { "MALLOC_SIZE",            MSV_GSTAT,   SQLITE_STATUS_MALLOC_SIZE          },
  { "MALLOC_COUNT",           MSV_GSTAT,   SQLITE_STATUS_MALLOC_COUNT         },
  { "PAGECACHE_USED",         MSV_GSTAT,   SQLITE_STATUS_PAGECACHE_USED       },
  { "PAGECACHE_OVERFLOW",     MSV_GSTAT,   SQLITE_STATUS_PAGECACHE_OVERFLOW   },
  { "PAGECACHE_SIZE",         MSV_GSTAT,   SQLITE_STATUS_PAGECACHE_SIZE       },
  { "PARSER_STACK",           MSV_GSTAT,   SQLITE_STATUS_PARSER_STACK         },
  { "DB_LOOKASIDE_USED",      MSV_DBSTAT, SQLITE_DBSTATUS_LOOKASIDE_USED      },
  { "DB_CACHE_USED",          MSV_DBSTAT, SQLITE_DBSTATUS_CACHE_USED          },
  { "DB_SCHEMA_USED",         MSV_DBSTAT, SQLITE_DBSTATUS_SCHEMA_USED         },
  { "DB_STMT_USED",           MSV_DBSTAT, SQLITE_DBSTATUS_STMT_USED           },
  { "DB_LOOKASIDE_HIT",       MSV_DBSTAT, SQLITE_DBSTATUS_LOOKASIDE_HIT       },
  { "DB_LOOKASIDE_MISS_SIZE", MSV_DBSTAT, SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE },
  { "DB_LOOKASIDE_MISS_FULL", MSV_DBSTAT, SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL },
  { "DB_CACHE_HIT",           MSV_DBSTAT, SQLITE_DBSTATUS_CACHE_HIT           },
  { "DB_CACHE_MISS",          MSV_DBSTAT, SQLITE_DBSTATUS_CACHE_MISS          },
  { "DB_CACHE_WRITE",         MSV_DBSTAT, SQLITE_DBSTATUS_CACHE_WRITE         },
  { "DB_DEFERRED_FKS",        MSV_DBSTAT, SQLITE_DBSTATUS_DEFERRED_FKS        },
  { "DB_CACHE_USED_SHARED",   MSV_DBSTAT, SQLITE_DBSTATUS_CACHE_USED_SHARED   },
  { "DB_CACHE_SPILL",         MSV_DBSTAT, SQLITE_DBSTATUS_CACHE_SPILL         },
#ifdef SQLITE_ENABLE_ZIPVFS
  { "ZIPVFS_CACHE_USED",      MSV_ZIPVFS, 231454 },
  { "ZIPVFS_CACHE_HIT",       MSV_ZIPVFS, 231455 },
  { "ZIPVFS_CACHE_MISS",      MSV_ZIPVFS, 231456 },
  { "ZIPVFS_CACHE_WRITE",     MSV_ZIPVFS, 231457 },
  { "ZIPVFS_DIRECT_READ",     MSV_ZIPVFS, 231458 },
  { "ZIPVFS_DIRECT_BYTES",    MSV_ZIPVFS, 231459 },
#endif /* SQLITE_ENABLE_ZIPVFS */
};
#define MSV_NROW (sizeof(aMemstatColumn)/sizeof(aMemstatColumn[0]))

/*
** Advance a memstat_cursor to its next row of output.
*/
static int memstatNext(sqlite3_vtab_cursor *cur){
................................................................................
    case MSV_DBSTAT: {
      int xCur, xHiwtr;
      sqlite3_db_status(pCur->db, aMemstatColumn[i].eOp, &xCur, &xHiwtr, 0);
      iCur = xCur;
      iHiwtr = xHiwtr;
      break;
    }
    case MSV_ZIPVFS: {
      sqlite3_file_control(pCur->db, 0, aMemstatColumn[i].eOp, (void*)&iCur);
      break;
    }
  }
  if( iCol==MSV_COLUMN_HIWTR ) iCur = iHiwtr;
  sqlite3_result_int64(ctx, iCur);
  return SQLITE_OK;
}

/*
................................................................................

/*
** Return TRUE if the cursor has been moved off of the last
** row of output.
*/
static int memstatEof(sqlite3_vtab_cursor *cur){
  memstat_cursor *pCur = (memstat_cursor*)cur;
  return pCur->iRowid>MSV_NROW;
}

/*
** This method is called to "rewind" the memstat_cursor object back
** to the first row of output.  This method is always called at least
** once prior to any call to memstatColumn() or memstatRowid() or 
** memstatEof().