Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Add a big comment to the top of test_vfstrace.c to explain how to compile and use that module. |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
a6a0fefbe503a2c81aa1847ced3bac21 |
User & Date: | drh 2011-05-20 13:26:58.320 |
Context
2011-05-20
| ||
20:42 | Adjustments to documentation hyperlinks to accommodate the new VFS documentation. (check-in: 139a8f53ae user: drh tags: trunk) | |
13:26 | Add a big comment to the top of test_vfstrace.c to explain how to compile and use that module. (check-in: a6a0fefbe5 user: drh tags: trunk) | |
01:50 | Fix the URI test script so that it works even if there is a subdirectory named "test". (check-in: 2018d4e108 user: drh tags: trunk) | |
Changes
Changes to src/test_vfstrace.c.
︙ | ︙ | |||
8 9 10 11 12 13 14 15 16 17 18 19 20 21 | ** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ****************************************************************************** ** ** This file contains code implements a VFS shim that writes diagnostic ** output for each VFS call, similar to "strace". */ #include <stdlib.h> #include <string.h> #include "sqlite3.h" /* ** An instance of this structure is attached to the each trace VFS to | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | ** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ****************************************************************************** ** ** This file contains code implements a VFS shim that writes diagnostic ** output for each VFS call, similar to "strace". ** ** USAGE: ** ** This source file exports a single symbol which is the name of a ** function: ** ** int vfstrace_register( ** const char *zTraceName, // Name of the newly constructed VFS ** const char *zOldVfsName, // Name of the underlying VFS ** int (*xOut)(const char*,void*), // Output routine. ex: fputs ** void *pOutArg, // 2nd argument to xOut. ex: stderr ** int makeDefault // Make the new VFS the default ** ); ** ** Applications that want to trace their VFS usage must provide a callback ** function with this prototype: ** ** int traceOutput(const char *zMessage, void *pAppData); ** ** This function will "output" the trace messages, where "output" can ** mean different things to different applications. The traceOutput function ** for the command-line shell (see shell.c) is "fputs" from the standard ** library, which means that all trace output is written on the stream ** specified by the second argument. In the case of the command-line shell ** the second argument is stderr. Other applications might choose to output ** trace information to a file, over a socket, or write it into a buffer. ** ** The vfstrace_register() function creates a new "shim" VFS named by ** the zTraceName parameter. A "shim" VFS is an SQLite backend that does ** not really perform the duties of a true backend, but simply filters or ** interprets VFS calls before passing them off to another VFS which does ** the actual work. In this case the other VFS - the one that does the ** real work - is identified by the second parameter, zOldVfsName. If ** the the 2nd parameter is NULL then the default VFS is used. The common ** case is for the 2nd parameter to be NULL. ** ** The third and fourth parameters are the pointer to the output function ** and the second argument to the output function. For the SQLite ** command-line shell, when the -vfstrace option is used, these parameters ** are fputs and stderr, respectively. ** ** The fifth argument is true (non-zero) to cause the newly created VFS ** to become the default VFS. The common case is for the fifth parameter ** to be true. ** ** The call to vfstrace_register() simply creates the shim VFS that does ** tracing. The application must also arrange to use the new VFS for ** all database connections that are created and for which tracing is ** desired. This can be done by specifying the trace VFS using URI filename ** notation, or by specifying the trace VFS as the 4th parameter to ** sqlite3_open_v2() or by making the trace VFS be the default (by setting ** the 5th parameter of vfstrace_register() to 1). ** ** ** ENABLING VFSTRACE IN A COMMAND-LINE SHELL ** ** The SQLite command line shell implemented by the shell.c source file ** can be used with this module. To compile in -vfstrace support, first ** gather this file (test_vfstrace.c), the shell source file (shell.c), ** and the SQLite amalgamation source files (sqlite3.c, sqlite3.h) into ** the working directory. Then compile using a command like the following: ** ** gcc -o sqlite3 -Os -I. -DSQLITE_ENABLE_VFSTRACE \ ** -DSQLITE_THREADSAFE=0 -DSQLITE_ENABLE_FTS3 -DSQLITE_ENABLE_RTREE \ ** -DHAVE_READLINE -DHAVE_USLEEP=1 \ ** shell.c test_vfstrace.c sqlite3.c -ldl -lreadline -lncurses ** ** The gcc command above works on Linux and provides (in addition to the ** -vfstrace option) support for FTS3 and FTS4, RTREE, and command-line ** editing using the readline library. The command-line shell does not ** use threads so we added -DSQLITE_THREADSAFE=0 just to make the code ** run a little faster. For compiling on a Mac, you'll probably need ** to omit the -DHAVE_READLINE, the -lreadline, and the -lncurses options. ** The compilation could be simplified to just this: ** ** gcc -DSQLITE_ENABLE_VFSTRACE \ ** shell.c test_vfstrace.c sqlite3.c -ldl -lpthread ** ** In this second example, all unnecessary options have been removed ** Note that since the code is now threadsafe, we had to add the -lpthread ** option to pull in the pthreads library. ** ** To cross-compile for windows using MinGW, a command like this might ** work: ** ** /opt/mingw/bin/i386-mingw32msvc-gcc -o sqlite3.exe -Os -I \ ** -DSQLITE_THREADSAFE=0 -DSQLITE_ENABLE_VFSTRACE \ ** shell.c test_vfstrace.c sqlite3.c ** ** Similar compiler commands will work on different systems. The key ** invariants are (1) you must have -DSQLITE_ENABLE_VFSTRACE so that ** the shell.c source file will know to include the -vfstrace command-line ** option and (2) you must compile and link the three source files ** shell,c, test_vfstrace.c, and sqlite3.c. */ #include <stdlib.h> #include <string.h> #include "sqlite3.h" /* ** An instance of this structure is attached to the each trace VFS to |
︙ | ︙ |