Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Add a timestamp to each osinst log entry, to facilitate merging multiple log files. |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | osinst |
Files: | files | file ages | folders |
SHA3-256: |
c9519c0cec3f0eae3ec4abe39fabbcc5 |
User & Date: | dan 2019-10-05 19:17:40.314 |
Context
2019-10-05
| ||
19:37 | Fix a problem in Makefile.msc on this branch. (check-in: ed3499a1a5 user: dan tags: osinst) | |
19:17 | Add a timestamp to each osinst log entry, to facilitate merging multiple log files. (check-in: c9519c0cec user: dan tags: osinst) | |
17:29 | Have sqlite3.c automatically turn on osinst logging for all connections. (check-in: eea231f81b user: dan tags: osinst) | |
Changes
Changes to src/test_osinst.c.
︙ | ︙ | |||
58 59 60 61 62 63 64 65 66 67 68 69 70 71 | ** CREATE VIRTUAL TABLE v USING vfslog('vfs.log'); ** ** creates a virtual table with 6 columns, as follows: ** ** CREATE TABLE v( ** event TEXT, // "xOpen", "xRead" etc. ** file TEXT, // Name of file this call applies to ** clicks INTEGER, // Time spent in call ** rc INTEGER, // Return value ** size INTEGER, // Bytes read or written ** offset INTEGER // File offset read or written ** ); */ | > | 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | ** CREATE VIRTUAL TABLE v USING vfslog('vfs.log'); ** ** creates a virtual table with 6 columns, as follows: ** ** CREATE TABLE v( ** event TEXT, // "xOpen", "xRead" etc. ** file TEXT, // Name of file this call applies to ** time INTEGER, // Timestamp ** clicks INTEGER, // Time spent in call ** rc INTEGER, // Return value ** size INTEGER, // Bytes read or written ** offset INTEGER // File offset read or written ** ); */ |
︙ | ︙ | |||
243 244 245 246 247 248 249 | } #else static sqlite3_uint64 vfslog_time(){ return 0; } #endif | | > | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 | } #else static sqlite3_uint64 vfslog_time(){ return 0; } #endif static void vfslog_call( sqlite3_vfs *, int, int, sqlite3_uint64, sqlite3_int64, int, int, int); static void vfslog_string(sqlite3_vfs *, const char *); /* ** Close an vfslog-file. */ static int vfslogClose(sqlite3_file *pFile){ sqlite3_uint64 t, t2; int rc = SQLITE_OK; VfslogFile *p = (VfslogFile *)pFile; t = vfslog_time(); if( p->pReal->pMethods ){ rc = p->pReal->pMethods->xClose(p->pReal); } t2 = vfslog_time() - t; vfslog_call(p->pVfslog, OS_CLOSE, p->iFileId, t, t2, rc, 0, 0); return rc; } /* ** Read data from an vfslog-file. */ static int vfslogRead( sqlite3_file *pFile, void *zBuf, int iAmt, sqlite_int64 iOfst ){ int rc; sqlite3_uint64 t, t2; VfslogFile *p = (VfslogFile *)pFile; t = vfslog_time(); rc = p->pReal->pMethods->xRead(p->pReal, zBuf, iAmt, iOfst); t2 = vfslog_time() - t; vfslog_call(p->pVfslog, OS_READ, p->iFileId, t, t2, rc, iAmt, (int)iOfst); return rc; } /* ** Write data to an vfslog-file. */ static int vfslogWrite( sqlite3_file *pFile, const void *z, int iAmt, sqlite_int64 iOfst ){ int rc; sqlite3_uint64 t, t2; VfslogFile *p = (VfslogFile *)pFile; t = vfslog_time(); rc = p->pReal->pMethods->xWrite(p->pReal, z, iAmt, iOfst); t2 = vfslog_time() - t; vfslog_call(p->pVfslog, OS_WRITE, p->iFileId, t, t2, rc, iAmt, (int)iOfst); return rc; } /* ** Truncate an vfslog-file. */ static int vfslogTruncate(sqlite3_file *pFile, sqlite_int64 size){ int rc; sqlite3_uint64 t, t2; VfslogFile *p = (VfslogFile *)pFile; t = vfslog_time(); rc = p->pReal->pMethods->xTruncate(p->pReal, size); t2 = vfslog_time() - t; vfslog_call(p->pVfslog, OS_TRUNCATE, p->iFileId, t, t2, rc, 0, (int)size); return rc; } /* ** Sync an vfslog-file. */ static int vfslogSync(sqlite3_file *pFile, int flags){ int rc; sqlite3_uint64 t, t2; VfslogFile *p = (VfslogFile *)pFile; t = vfslog_time(); rc = p->pReal->pMethods->xSync(p->pReal, flags); t2 = vfslog_time() - t; vfslog_call(p->pVfslog, OS_SYNC, p->iFileId, t, t2, rc, flags, 0); return rc; } /* ** Return the current file-size of an vfslog-file. */ static int vfslogFileSize(sqlite3_file *pFile, sqlite_int64 *pSize){ int rc; sqlite3_uint64 t, t2; VfslogFile *p = (VfslogFile *)pFile; t = vfslog_time(); rc = p->pReal->pMethods->xFileSize(p->pReal, pSize); t2 = vfslog_time() - t; vfslog_call(p->pVfslog, OS_FILESIZE, p->iFileId, t, t2, rc, 0, (int)*pSize); return rc; } /* ** Lock an vfslog-file. */ static int vfslogLock(sqlite3_file *pFile, int eLock){ int rc; sqlite3_uint64 t, t2; VfslogFile *p = (VfslogFile *)pFile; t = vfslog_time(); rc = p->pReal->pMethods->xLock(p->pReal, eLock); t2 = vfslog_time() - t; vfslog_call(p->pVfslog, OS_LOCK, p->iFileId, t, t2, rc, eLock, 0); return rc; } /* ** Unlock an vfslog-file. */ static int vfslogUnlock(sqlite3_file *pFile, int eLock){ int rc; sqlite3_uint64 t, t2; VfslogFile *p = (VfslogFile *)pFile; t = vfslog_time(); rc = p->pReal->pMethods->xUnlock(p->pReal, eLock); t2 = vfslog_time() - t; vfslog_call(p->pVfslog, OS_UNLOCK, p->iFileId, t, t2, rc, eLock, 0); return rc; } /* ** Check if another file-handle holds a RESERVED lock on an vfslog-file. */ static int vfslogCheckReservedLock(sqlite3_file *pFile, int *pResOut){ int rc; sqlite3_uint64 t, t2; VfslogFile *p = (VfslogFile *)pFile; t = vfslog_time(); rc = p->pReal->pMethods->xCheckReservedLock(p->pReal, pResOut); t2 = vfslog_time() - t; vfslog_call(p->pVfslog, OS_CHECKRESERVEDLOCK, p->iFileId, t,t2,rc,*pResOut,0); return rc; } /* ** File control method. For custom operations on an vfslog-file. */ static int vfslogFileControl(sqlite3_file *pFile, int op, void *pArg){ VfslogFile *p = (VfslogFile *)pFile; int rc = p->pReal->pMethods->xFileControl(p->pReal, op, pArg); if( op==SQLITE_FCNTL_VFSNAME && rc==SQLITE_OK ){ *(char**)pArg = sqlite3_mprintf("vfslog/%z", *(char**)pArg); } return rc; } /* ** Return the sector-size in bytes for an vfslog-file. */ static int vfslogSectorSize(sqlite3_file *pFile){ int rc; sqlite3_uint64 t, t2; VfslogFile *p = (VfslogFile *)pFile; t = vfslog_time(); rc = p->pReal->pMethods->xSectorSize(p->pReal); t2 = vfslog_time() - t; vfslog_call(p->pVfslog, OS_SECTORSIZE, p->iFileId, t, t2, rc, 0, 0); return rc; } /* ** Return the device characteristic flags supported by an vfslog-file. */ static int vfslogDeviceCharacteristics(sqlite3_file *pFile){ int rc; sqlite3_uint64 t, t2; VfslogFile *p = (VfslogFile *)pFile; t = vfslog_time(); rc = p->pReal->pMethods->xDeviceCharacteristics(p->pReal); t2 = vfslog_time() - t; vfslog_call(p->pVfslog, OS_DEVCHAR, p->iFileId, t, t2, rc, 0, 0); return rc; } static int vfslogShmLock(sqlite3_file *pFile, int ofst, int n, int flags){ int rc; sqlite3_uint64 t, t2; VfslogFile *p = (VfslogFile *)pFile; t = vfslog_time(); rc = p->pReal->pMethods->xShmLock(p->pReal, ofst, n, flags); t2 = vfslog_time() - t; vfslog_call(p->pVfslog, OS_SHMLOCK, p->iFileId, t, t2, rc, 0, 0); return rc; } static int vfslogShmMap( sqlite3_file *pFile, int iRegion, int szRegion, int isWrite, volatile void **pp ){ int rc; sqlite3_uint64 t, t2; VfslogFile *p = (VfslogFile *)pFile; t = vfslog_time(); rc = p->pReal->pMethods->xShmMap(p->pReal, iRegion, szRegion, isWrite, pp); t2 = vfslog_time() - t; vfslog_call(p->pVfslog, OS_SHMMAP, p->iFileId, t, t2, rc, 0, 0); return rc; } static void vfslogShmBarrier(sqlite3_file *pFile){ sqlite3_uint64 t, t2; VfslogFile *p = (VfslogFile *)pFile; t = vfslog_time(); p->pReal->pMethods->xShmBarrier(p->pReal); t2 = vfslog_time() - t; vfslog_call(p->pVfslog, OS_SHMBARRIER, p->iFileId, t, t2, SQLITE_OK, 0, 0); } static int vfslogShmUnmap(sqlite3_file *pFile, int deleteFlag){ int rc; sqlite3_uint64 t, t2; VfslogFile *p = (VfslogFile *)pFile; t = vfslog_time(); rc = p->pReal->pMethods->xShmUnmap(p->pReal, deleteFlag); t2 = vfslog_time() - t; vfslog_call(p->pVfslog, OS_SHMUNMAP, p->iFileId, t, t2, rc, 0, 0); return rc; } /* ** Open an vfslog file handle. */ static int vfslogOpen( sqlite3_vfs *pVfs, const char *zName, sqlite3_file *pFile, int flags, int *pOutFlags ){ int rc; sqlite3_uint64 t, t2; VfslogFile *p = (VfslogFile *)pFile; VfslogVfs *pLog = (VfslogVfs *)pVfs; pFile->pMethods = &vfslog_io_methods; p->pReal = (sqlite3_file *)&p[1]; p->pVfslog = pVfs; p->iFileId = ++pLog->iNextFileId; t = vfslog_time(); rc = REALVFS(pVfs)->xOpen(REALVFS(pVfs), zName, p->pReal, flags, pOutFlags); t2 = vfslog_time() - t; vfslog_call(pVfs, OS_OPEN, p->iFileId, t, t2, rc, 0, 0); vfslog_string(pVfs, zName); return rc; } /* ** Delete the file located at zPath. If the dirSync argument is true, ** ensure the file-system modifications are synced to disk before ** returning. */ static int vfslogDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){ int rc; sqlite3_uint64 t, t2; t = vfslog_time(); rc = REALVFS(pVfs)->xDelete(REALVFS(pVfs), zPath, dirSync); t2 = vfslog_time() - t; vfslog_call(pVfs, OS_DELETE, 0, t, t2, rc, dirSync, 0); vfslog_string(pVfs, zPath); return rc; } /* ** Test for access permissions. Return true if the requested permission ** is available, or false otherwise. */ static int vfslogAccess( sqlite3_vfs *pVfs, const char *zPath, int flags, int *pResOut ){ int rc; sqlite3_uint64 t, t2; t = vfslog_time(); rc = REALVFS(pVfs)->xAccess(REALVFS(pVfs), zPath, flags, pResOut); t2 = vfslog_time() - t; vfslog_call(pVfs, OS_ACCESS, 0, t, t2, rc, flags, *pResOut); vfslog_string(pVfs, zPath); return rc; } /* ** Populate buffer zOut with the full canonical pathname corresponding ** to the pathname in zPath. zOut is guaranteed to point to a buffer |
︙ | ︙ | |||
649 650 651 652 653 654 655 656 657 658 659 660 661 662 | p[3] = (unsigned char)v; } static void vfslog_call( sqlite3_vfs *pVfs, int eEvent, int iFileid, sqlite3_int64 nClick, int return_code, int size, int offset ){ VfslogVfs *p = (VfslogVfs *)pVfs; unsigned char *zRec; | > | | > > | | | | | 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 | p[3] = (unsigned char)v; } static void vfslog_call( sqlite3_vfs *pVfs, int eEvent, int iFileid, sqlite3_uint64 tStamp, sqlite3_int64 nClick, int return_code, int size, int offset ){ VfslogVfs *p = (VfslogVfs *)pVfs; unsigned char *zRec; if( (32+p->nBuf)>sizeof(p->aBuf) ){ vfslog_flush(p); } zRec = (unsigned char *)&p->aBuf[p->nBuf]; vfslogPut32bits(&zRec[0], eEvent); vfslogPut32bits(&zRec[4], iFileid); vfslogPut32bits(&zRec[8], (unsigned int)((tStamp>>32)&0xffffffff)); vfslogPut32bits(&zRec[12], (unsigned int)(tStamp&0xffffffff)); vfslogPut32bits(&zRec[16], (unsigned int)(nClick&0xffffffff)); vfslogPut32bits(&zRec[20], return_code); vfslogPut32bits(&zRec[24], size); vfslogPut32bits(&zRec[28], offset); p->nBuf += 32; } static void vfslog_string(sqlite3_vfs *pVfs, const char *zStr){ VfslogVfs *p = (VfslogVfs *)pVfs; unsigned char *zRec; int nStr = zStr ? (int)strlen(zStr) : 0; if( (4+nStr+p->nBuf)>sizeof(p->aBuf) ){ |
︙ | ︙ | |||
755 756 757 758 759 760 761 762 763 764 765 | vfslog_finalize(p); } return rc; } int sqlite3_vfslog_annotate(const char *zVfs, const char *zMsg){ sqlite3_vfs *pVfs; pVfs = sqlite3_vfs_find(zVfs); if( !pVfs || pVfs->xOpen!=vfslogOpen ){ return SQLITE_ERROR; } | > | | 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 | vfslog_finalize(p); } return rc; } int sqlite3_vfslog_annotate(const char *zVfs, const char *zMsg){ sqlite3_vfs *pVfs; sqlite3_uint64 t = vfslog_time(); pVfs = sqlite3_vfs_find(zVfs); if( !pVfs || pVfs->xOpen!=vfslogOpen ){ return SQLITE_ERROR; } vfslog_call(pVfs, OS_ANNOTATE, 0, t, 0, 0, 0, 0); vfslog_string(pVfs, zMsg); return SQLITE_OK; } static const char *vfslog_eventname(int eEvent){ const char *zEvent = 0; |
︙ | ︙ | |||
897 898 899 900 901 902 903 | flags = SQLITE_OPEN_READWRITE|SQLITE_OPEN_MASTER_JOURNAL; rc = pVfs->xOpen(pVfs, p->zFile, p->pFd, flags, &flags); if( rc==SQLITE_OK ){ p->pFd->pMethods->xFileSize(p->pFd, &p->nByte); sqlite3_declare_vtab(db, | | | 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 | flags = SQLITE_OPEN_READWRITE|SQLITE_OPEN_MASTER_JOURNAL; rc = pVfs->xOpen(pVfs, p->zFile, p->pFd, flags, &flags); if( rc==SQLITE_OK ){ p->pFd->pMethods->xFileSize(p->pFd, &p->nByte); sqlite3_declare_vtab(db, "CREATE TABLE xxx(event, file, time, click, rc, size, offset)" ); *ppVtab = &p->base; }else{ sqlite3_free(p); } return rc; |
︙ | ︙ | |||
969 970 971 972 973 974 975 | VfslogVtab *p = (VfslogVtab *)pCursor->pVtab; int rc = SQLITE_OK; int nRead; sqlite3_free(pCsr->zTransient); pCsr->zTransient = 0; | | | 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 | VfslogVtab *p = (VfslogVtab *)pCursor->pVtab; int rc = SQLITE_OK; int nRead; sqlite3_free(pCsr->zTransient); pCsr->zTransient = 0; nRead = 32; if( pCsr->iOffset+nRead<=p->nByte ){ int eEvent; rc = p->pFd->pMethods->xRead(p->pFd, pCsr->aBuf, nRead, pCsr->iOffset); eEvent = get32bits(pCsr->aBuf); if( (rc==SQLITE_OK) && (eEvent==OS_OPEN || eEvent==OS_DELETE || eEvent==OS_ACCESS) |
︙ | ︙ | |||
1033 1034 1035 1036 1037 1038 1039 | } static int vlogColumn( sqlite3_vtab_cursor *pCursor, sqlite3_context *ctx, int i ){ | < < > > > > > > > > | > > | 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 | } static int vlogColumn( sqlite3_vtab_cursor *pCursor, sqlite3_context *ctx, int i ){ VfslogCsr *pCsr = (VfslogCsr *)pCursor; assert( i<7 ); switch( i ){ case 0: { unsigned int val = get32bits(&pCsr->aBuf[0]); sqlite3_result_text(ctx, vfslog_eventname(val), -1, SQLITE_STATIC); break; } case 1: { unsigned int val = get32bits(&pCsr->aBuf[4]); char *zStr = pCsr->zTransient; if( val!=0 && val<(unsigned)pCsr->nFile ){ zStr = pCsr->azFile[val]; } sqlite3_result_text(ctx, zStr, -1, SQLITE_TRANSIENT); break; } case 2: { unsigned int v1 = get32bits(&pCsr->aBuf[8]); unsigned int v2 = get32bits(&pCsr->aBuf[12]); sqlite3_result_int64(ctx,(((sqlite3_int64)v1) << 32) + (sqlite3_int64)v2); break; } default: { unsigned int val = get32bits(&pCsr->aBuf[4*(i+1)]); sqlite3_result_int(ctx, val); break; } } return SQLITE_OK; } static int vlogRowid(sqlite3_vtab_cursor *pCursor, sqlite_int64 *pRowid){ VfslogCsr *pCsr = (VfslogCsr *)pCursor; |
︙ | ︙ |
Added tool/osinst2sql.c.
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | /* ****************************************************************************** */ #include <sqlite3.h> #include <assert.h> #include <stdio.h> int sqlite3_vfslog_register(sqlite3 *db); static int xCallback(void *pUnused, int nArg, char **azArg, char **azName){ char *zPrint = 0; assert( nArg==7 ); zPrint = sqlite3_mprintf( "INSERT INTO osinst VALUES(%Q, %Q, %s, %s, %s, %s, %s);", azArg[0], azArg[1], azArg[2], azArg[3], azArg[4], azArg[5], azArg[6] ); printf("%s\n", zPrint); sqlite3_free(zPrint); return SQLITE_OK; } int main(int argc, char **argv){ sqlite3 *db = 0; int i; sqlite3_open("", &db); sqlite3_vfslog_register(db); printf("BEGIN;\n"); printf("CREATE TABLE IF NOT EXISTS osinst(\n"); printf(" event TEXT, -- xOpen, xRead etc.\n"); printf(" file TEXT, -- Name of file this call applies to\n"); printf(" time INTEGER, -- Timestamp\n"); printf(" clicks INTEGER, -- Time spent in call\n"); printf(" rc INTEGER, -- Return value\n"); printf(" size INTEGER, -- Bytes read or written\n"); printf(" offset INTEGER -- File offset read or written\n"); printf(");\n"); for(i=1; i<argc; i++){ char *zSql = 0; sqlite3_exec(db, "DROP TABLE IF EXISTS osinst;", 0, 0, 0); zSql = sqlite3_mprintf( "CREATE VIRTUAL TABLE osinst USING vfslog(%Q)", argv[i] ); sqlite3_exec(db, zSql, 0, 0, 0); sqlite3_free(zSql); sqlite3_exec(db, "SELECT * FROM osinst", xCallback, 0, 0); } printf("COMMIT;\n"); sqlite3_close(db); return 0; } |