OLD | NEW |
1 /* | 1 /* |
2 ** 2008 April 10 | 2 ** 2008 April 10 |
3 ** | 3 ** |
4 ** The author disclaims copyright to this source code. In place of | 4 ** The author disclaims copyright to this source code. In place of |
5 ** a legal notice, here is a blessing: | 5 ** a legal notice, here is a blessing: |
6 ** | 6 ** |
7 ** May you do good and not evil. | 7 ** May you do good and not evil. |
8 ** May you find forgiveness for yourself and forgive others. | 8 ** May you find forgiveness for yourself and forgive others. |
9 ** May you share freely, never taking more than you give. | 9 ** May you share freely, never taking more than you give. |
10 ** | 10 ** |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 ** event TEXT, // "xOpen", "xRead" etc. | 63 ** event TEXT, // "xOpen", "xRead" etc. |
64 ** file TEXT, // Name of file this call applies to | 64 ** file TEXT, // Name of file this call applies to |
65 ** clicks INTEGER, // Time spent in call | 65 ** clicks INTEGER, // Time spent in call |
66 ** rc INTEGER, // Return value | 66 ** rc INTEGER, // Return value |
67 ** size INTEGER, // Bytes read or written | 67 ** size INTEGER, // Bytes read or written |
68 ** offset INTEGER // File offset read or written | 68 ** offset INTEGER // File offset read or written |
69 ** ); | 69 ** ); |
70 */ | 70 */ |
71 | 71 |
72 #include "sqlite3.h" | 72 #include "sqlite3.h" |
| 73 |
| 74 #include "os_setup.h" |
| 75 #if SQLITE_OS_WIN |
| 76 # include "os_win.h" |
| 77 #endif |
| 78 |
73 #include <string.h> | 79 #include <string.h> |
74 #include <assert.h> | 80 #include <assert.h> |
75 | 81 |
76 | 82 |
77 /* | 83 /* |
78 ** Maximum pathname length supported by the vfslog backend. | 84 ** Maximum pathname length supported by the vfslog backend. |
79 */ | 85 */ |
80 #define INST_MAX_PATHNAME 512 | 86 #define INST_MAX_PATHNAME 512 |
81 | 87 |
82 #define OS_ACCESS 1 | 88 #define OS_ACCESS 1 |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 }; | 220 }; |
215 | 221 |
216 #if SQLITE_OS_UNIX && !defined(NO_GETTOD) | 222 #if SQLITE_OS_UNIX && !defined(NO_GETTOD) |
217 #include <sys/time.h> | 223 #include <sys/time.h> |
218 static sqlite3_uint64 vfslog_time(){ | 224 static sqlite3_uint64 vfslog_time(){ |
219 struct timeval sTime; | 225 struct timeval sTime; |
220 gettimeofday(&sTime, 0); | 226 gettimeofday(&sTime, 0); |
221 return sTime.tv_usec + (sqlite3_uint64)sTime.tv_sec * 1000000; | 227 return sTime.tv_usec + (sqlite3_uint64)sTime.tv_sec * 1000000; |
222 } | 228 } |
223 #elif SQLITE_OS_WIN | 229 #elif SQLITE_OS_WIN |
224 #include <windows.h> | |
225 #include <time.h> | 230 #include <time.h> |
226 static sqlite3_uint64 vfslog_time(){ | 231 static sqlite3_uint64 vfslog_time(){ |
227 FILETIME ft; | 232 FILETIME ft; |
228 sqlite3_uint64 u64time = 0; | 233 sqlite3_uint64 u64time = 0; |
229 | 234 |
230 GetSystemTimeAsFileTime(&ft); | 235 GetSystemTimeAsFileTime(&ft); |
231 | 236 |
232 u64time |= ft.dwHighDateTime; | 237 u64time |= ft.dwHighDateTime; |
233 u64time <<= 32; | 238 u64time <<= 32; |
234 u64time |= ft.dwLowDateTime; | 239 u64time |= ft.dwLowDateTime; |
235 | 240 |
236 /* ft is 100-nanosecond intervals, we want microseconds */ | 241 /* ft is 100-nanosecond intervals, we want microseconds */ |
237 return u64time /(sqlite3_uint64)10; | 242 return u64time /(sqlite3_uint64)10; |
238 } | 243 } |
239 #else | 244 #else |
240 static sqlite3_uint64 vfslog_time(){ | 245 static sqlite3_uint64 vfslog_time(){ |
241 return 0; | 246 return 0; |
242 } | 247 } |
243 #endif | 248 #endif |
244 | 249 |
245 static void vfslog_call(sqlite3_vfs *, int, int, int, int, int, int); | 250 static void vfslog_call(sqlite3_vfs *, int, int, sqlite3_int64, int, int, int); |
246 static void vfslog_string(sqlite3_vfs *, const char *); | 251 static void vfslog_string(sqlite3_vfs *, const char *); |
247 | 252 |
248 /* | 253 /* |
249 ** Close an vfslog-file. | 254 ** Close an vfslog-file. |
250 */ | 255 */ |
251 static int vfslogClose(sqlite3_file *pFile){ | 256 static int vfslogClose(sqlite3_file *pFile){ |
252 sqlite3_uint64 t; | 257 sqlite3_uint64 t; |
253 int rc = SQLITE_OK; | 258 int rc = SQLITE_OK; |
254 VfslogFile *p = (VfslogFile *)pFile; | 259 VfslogFile *p = (VfslogFile *)pFile; |
255 | 260 |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 t = vfslog_time() - t; | 387 t = vfslog_time() - t; |
383 vfslog_call(p->pVfslog, OS_CHECKRESERVEDLOCK, p->iFileId, t, rc, *pResOut, 0); | 388 vfslog_call(p->pVfslog, OS_CHECKRESERVEDLOCK, p->iFileId, t, rc, *pResOut, 0); |
384 return rc; | 389 return rc; |
385 } | 390 } |
386 | 391 |
387 /* | 392 /* |
388 ** File control method. For custom operations on an vfslog-file. | 393 ** File control method. For custom operations on an vfslog-file. |
389 */ | 394 */ |
390 static int vfslogFileControl(sqlite3_file *pFile, int op, void *pArg){ | 395 static int vfslogFileControl(sqlite3_file *pFile, int op, void *pArg){ |
391 VfslogFile *p = (VfslogFile *)pFile; | 396 VfslogFile *p = (VfslogFile *)pFile; |
392 return p->pReal->pMethods->xFileControl(p->pReal, op, pArg); | 397 int rc = p->pReal->pMethods->xFileControl(p->pReal, op, pArg); |
| 398 if( op==SQLITE_FCNTL_VFSNAME && rc==SQLITE_OK ){ |
| 399 *(char**)pArg = sqlite3_mprintf("vfslog/%z", *(char**)pArg); |
| 400 } |
| 401 return rc; |
393 } | 402 } |
394 | 403 |
395 /* | 404 /* |
396 ** Return the sector-size in bytes for an vfslog-file. | 405 ** Return the sector-size in bytes for an vfslog-file. |
397 */ | 406 */ |
398 static int vfslogSectorSize(sqlite3_file *pFile){ | 407 static int vfslogSectorSize(sqlite3_file *pFile){ |
399 int rc; | 408 int rc; |
400 sqlite3_uint64 t; | 409 sqlite3_uint64 t; |
401 VfslogFile *p = (VfslogFile *)pFile; | 410 VfslogFile *p = (VfslogFile *)pFile; |
402 t = vfslog_time(); | 411 t = vfslog_time(); |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
637 p[0] = v>>24; | 646 p[0] = v>>24; |
638 p[1] = v>>16; | 647 p[1] = v>>16; |
639 p[2] = v>>8; | 648 p[2] = v>>8; |
640 p[3] = v; | 649 p[3] = v; |
641 } | 650 } |
642 | 651 |
643 static void vfslog_call( | 652 static void vfslog_call( |
644 sqlite3_vfs *pVfs, | 653 sqlite3_vfs *pVfs, |
645 int eEvent, | 654 int eEvent, |
646 int iFileid, | 655 int iFileid, |
647 int nClick, | 656 sqlite3_int64 nClick, |
648 int return_code, | 657 int return_code, |
649 int size, | 658 int size, |
650 int offset | 659 int offset |
651 ){ | 660 ){ |
652 VfslogVfs *p = (VfslogVfs *)pVfs; | 661 VfslogVfs *p = (VfslogVfs *)pVfs; |
653 unsigned char *zRec; | 662 unsigned char *zRec; |
654 if( (24+p->nBuf)>sizeof(p->aBuf) ){ | 663 if( (24+p->nBuf)>sizeof(p->aBuf) ){ |
655 vfslog_flush(p); | 664 vfslog_flush(p); |
656 } | 665 } |
657 zRec = (unsigned char *)&p->aBuf[p->nBuf]; | 666 zRec = (unsigned char *)&p->aBuf[p->nBuf]; |
658 put32bits(&zRec[0], eEvent); | 667 put32bits(&zRec[0], eEvent); |
659 put32bits(&zRec[4], iFileid); | 668 put32bits(&zRec[4], iFileid); |
660 put32bits(&zRec[8], nClick); | 669 put32bits(&zRec[8], (unsigned int)(nClick&0xffff)); |
661 put32bits(&zRec[12], return_code); | 670 put32bits(&zRec[12], return_code); |
662 put32bits(&zRec[16], size); | 671 put32bits(&zRec[16], size); |
663 put32bits(&zRec[20], offset); | 672 put32bits(&zRec[20], offset); |
664 p->nBuf += 24; | 673 p->nBuf += 24; |
665 } | 674 } |
666 | 675 |
667 static void vfslog_string(sqlite3_vfs *pVfs, const char *zStr){ | 676 static void vfslog_string(sqlite3_vfs *pVfs, const char *zStr){ |
668 VfslogVfs *p = (VfslogVfs *)pVfs; | 677 VfslogVfs *p = (VfslogVfs *)pVfs; |
669 unsigned char *zRec; | 678 unsigned char *zRec; |
670 int nStr = zStr ? strlen(zStr) : 0; | 679 int nStr = zStr ? (int)strlen(zStr) : 0; |
671 if( (4+nStr+p->nBuf)>sizeof(p->aBuf) ){ | 680 if( (4+nStr+p->nBuf)>sizeof(p->aBuf) ){ |
672 vfslog_flush(p); | 681 vfslog_flush(p); |
673 } | 682 } |
674 zRec = (unsigned char *)&p->aBuf[p->nBuf]; | 683 zRec = (unsigned char *)&p->aBuf[p->nBuf]; |
675 put32bits(&zRec[0], nStr); | 684 put32bits(&zRec[0], nStr); |
676 if( zStr ){ | 685 if( zStr ){ |
677 memcpy(&zRec[4], zStr, nStr); | 686 memcpy(&zRec[4], zStr, nStr); |
678 } | 687 } |
679 p->nBuf += (4 + nStr); | 688 p->nBuf += (4 + nStr); |
680 } | 689 } |
(...skipping 28 matching lines...) Expand all Loading... |
709 int flags; | 718 int flags; |
710 int rc; | 719 int rc; |
711 char *zFile; | 720 char *zFile; |
712 int nVfs; | 721 int nVfs; |
713 | 722 |
714 pParent = sqlite3_vfs_find(zParentVfs); | 723 pParent = sqlite3_vfs_find(zParentVfs); |
715 if( !pParent ){ | 724 if( !pParent ){ |
716 return SQLITE_ERROR; | 725 return SQLITE_ERROR; |
717 } | 726 } |
718 | 727 |
719 nVfs = strlen(zVfs); | 728 nVfs = (int)strlen(zVfs); |
720 nByte = sizeof(VfslogVfs) + pParent->szOsFile + nVfs+1+pParent->mxPathname+1; | 729 nByte = sizeof(VfslogVfs) + pParent->szOsFile + nVfs+1+pParent->mxPathname+1; |
721 p = (VfslogVfs *)sqlite3_malloc(nByte); | 730 p = (VfslogVfs *)sqlite3_malloc(nByte); |
722 memset(p, 0, nByte); | 731 memset(p, 0, nByte); |
723 | 732 |
724 p->pVfs = pParent; | 733 p->pVfs = pParent; |
725 p->pLog = (sqlite3_file *)&p[1]; | 734 p->pLog = (sqlite3_file *)&p[1]; |
726 memcpy(&p->base, &vfslog_vfs, sizeof(sqlite3_vfs)); | 735 memcpy(&p->base, &vfslog_vfs, sizeof(sqlite3_vfs)); |
727 p->base.zName = &((char *)p->pLog)[pParent->szOsFile]; | 736 p->base.zName = &((char *)p->pLog)[pParent->szOsFile]; |
728 p->base.szOsFile += pParent->szOsFile; | 737 p->base.szOsFile += pParent->szOsFile; |
729 memcpy((char *)p->base.zName, zVfs, nVfs); | 738 memcpy((char *)p->base.zName, zVfs, nVfs); |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1032 assert( i<7 ); | 1041 assert( i<7 ); |
1033 val = get32bits(&pCsr->aBuf[4*i]); | 1042 val = get32bits(&pCsr->aBuf[4*i]); |
1034 | 1043 |
1035 switch( i ){ | 1044 switch( i ){ |
1036 case 0: { | 1045 case 0: { |
1037 sqlite3_result_text(ctx, vfslog_eventname(val), -1, SQLITE_STATIC); | 1046 sqlite3_result_text(ctx, vfslog_eventname(val), -1, SQLITE_STATIC); |
1038 break; | 1047 break; |
1039 } | 1048 } |
1040 case 1: { | 1049 case 1: { |
1041 char *zStr = pCsr->zTransient; | 1050 char *zStr = pCsr->zTransient; |
1042 if( val!=0 && val<pCsr->nFile ){ | 1051 if( val!=0 && val<(unsigned)pCsr->nFile ){ |
1043 zStr = pCsr->azFile[val]; | 1052 zStr = pCsr->azFile[val]; |
1044 } | 1053 } |
1045 sqlite3_result_text(ctx, zStr, -1, SQLITE_TRANSIENT); | 1054 sqlite3_result_text(ctx, zStr, -1, SQLITE_TRANSIENT); |
1046 break; | 1055 break; |
1047 } | 1056 } |
1048 default: | 1057 default: |
1049 sqlite3_result_int(ctx, val); | 1058 sqlite3_result_int(ctx, val); |
1050 break; | 1059 break; |
1051 } | 1060 } |
1052 | 1061 |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1202 | 1211 |
1203 return TCL_OK; | 1212 return TCL_OK; |
1204 } | 1213 } |
1205 | 1214 |
1206 int SqlitetestOsinst_Init(Tcl_Interp *interp){ | 1215 int SqlitetestOsinst_Init(Tcl_Interp *interp){ |
1207 Tcl_CreateObjCommand(interp, "vfslog", test_vfslog, 0, 0); | 1216 Tcl_CreateObjCommand(interp, "vfslog", test_vfslog, 0, 0); |
1208 return TCL_OK; | 1217 return TCL_OK; |
1209 } | 1218 } |
1210 | 1219 |
1211 #endif /* SQLITE_TEST */ | 1220 #endif /* SQLITE_TEST */ |
OLD | NEW |