/ Check-in [9de33768ff]
Login

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

Overview
Comment:Experimental API extension for recovering the current trace and profile callbacks on a database connection.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | get-trace
Files: files | file ages | folders
SHA1: 9de33768fff2d8952fdff552d918da96e5267e5d
User & Date: drh 2015-05-12 21:27:36
Context
2015-05-12
23:20
Modify the new functions to make them return a standard return code. check-in: 02f694d5ba user: mistachkin tags: get-trace
21:27
Experimental API extension for recovering the current trace and profile callbacks on a database connection. check-in: 9de33768ff user: drh tags: get-trace
19:10
Attempt to get DBSTAT to compile without warnings across all build configurations. check-in: c3cbe3b06e user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/main.c.

  1758   1758     sqlite3_mutex_enter(db->mutex);
  1759   1759     pOld = db->pTraceArg;
  1760   1760     db->xTrace = xTrace;
  1761   1761     db->pTraceArg = pArg;
  1762   1762     sqlite3_mutex_leave(db->mutex);
  1763   1763     return pOld;
  1764   1764   }
         1765  +/*
         1766  +** Return the curren trace function and argument.
         1767  +*/
         1768  +void sqlite3_get_trace(
         1769  +  const sqlite3 *db,
         1770  +  void (**pxTrace)(void*,const char*),
         1771  +  void **ppArg
         1772  +){
         1773  +#ifdef SQLITE_ENABLE_API_ARMOR
         1774  +  if( !sqlite3SafetyCheckOk(db) ){
         1775  +    (void)SQLITE_MISUSE_BKPT;
         1776  +    return 0;
         1777  +  }
         1778  +#endif
         1779  +  *pxTrace = db->xTrace;
         1780  +  *ppArg = db->pTraceArg;
         1781  +}
  1765   1782   /*
  1766   1783   ** Register a profile function.  The pArg from the previously registered 
  1767   1784   ** profile function is returned.  
  1768   1785   **
  1769   1786   ** A NULL profile function means that no profiling is executes.  A non-NULL
  1770   1787   ** profile is a pointer to a function that is invoked at the conclusion of
  1771   1788   ** each SQL statement that is run.
................................................................................
  1786   1803     sqlite3_mutex_enter(db->mutex);
  1787   1804     pOld = db->pProfileArg;
  1788   1805     db->xProfile = xProfile;
  1789   1806     db->pProfileArg = pArg;
  1790   1807     sqlite3_mutex_leave(db->mutex);
  1791   1808     return pOld;
  1792   1809   }
         1810  +/*
         1811  +** Return the curren trace function and argument.
         1812  +*/
         1813  +void sqlite3_get_profile(
         1814  +  const sqlite3 *db,
         1815  +  void (**pxProfile)(void*,const char*,sqlite3_uint64),
         1816  +  void **ppArg
         1817  +){
         1818  +#ifdef SQLITE_ENABLE_API_ARMOR
         1819  +  if( !sqlite3SafetyCheckOk(db) ){
         1820  +    (void)SQLITE_MISUSE_BKPT;
         1821  +    return 0;
         1822  +  }
         1823  +#endif
         1824  +  *pxProfile = db->xProfile;
         1825  +  *ppArg = db->pProfileArg;
         1826  +}
  1793   1827   #endif /* SQLITE_OMIT_TRACE */
  1794   1828   
  1795   1829   /*
  1796   1830   ** Register a function to be invoked when a transaction commits.
  1797   1831   ** If the invoked function returns non-zero, then the commit becomes a
  1798   1832   ** rollback.
  1799   1833   */

Changes to src/sqlite.h.in.

  2668   2668   #define SQLITE_COPY                  0   /* No longer used */
  2669   2669   #define SQLITE_RECURSIVE            33   /* NULL            NULL            */
  2670   2670   
  2671   2671   /*
  2672   2672   ** CAPI3REF: Tracing And Profiling Functions
  2673   2673   ** METHOD: sqlite3
  2674   2674   **
  2675         -** These routines register callback functions that can be used for
         2675  +** These routines control callback functions that can be used for
  2676   2676   ** tracing and profiling the execution of SQL statements.
  2677   2677   **
  2678   2678   ** ^The callback function registered by sqlite3_trace() is invoked at
  2679   2679   ** various times when an SQL statement is being run by [sqlite3_step()].
  2680   2680   ** ^The sqlite3_trace() callback is invoked with a UTF-8 rendering of the
  2681   2681   ** SQL statement text as the statement first begins executing.
  2682   2682   ** ^(Additional sqlite3_trace() callbacks might occur
  2683   2683   ** as each triggered subprogram is entered.  The callbacks for triggers
  2684   2684   ** contain a UTF-8 SQL comment that identifies the trigger.)^
         2685  +**
         2686  +** ^The [sqlite3_get_trace(D,X,P)] interface writes into X and P the
         2687  +** values of the trace callback and pointer set by the most recent
         2688  +** [sqlite3_trace()] call on the same [database connection] D.
  2685   2689   **
  2686   2690   ** The [SQLITE_TRACE_SIZE_LIMIT] compile-time option can be used to limit
  2687   2691   ** the length of [bound parameter] expansion in the output of sqlite3_trace().
  2688   2692   **
  2689   2693   ** ^The callback function registered by sqlite3_profile() is invoked
  2690   2694   ** as each SQL statement finishes.  ^The profile callback contains
  2691   2695   ** the original statement text and an estimate of wall-clock time
  2692   2696   ** of how long that statement took to run.  ^The profile callback
  2693   2697   ** time is in units of nanoseconds, however the current implementation
  2694   2698   ** is only capable of millisecond resolution so the six least significant
  2695   2699   ** digits in the time are meaningless.  Future versions of SQLite
  2696         -** might provide greater resolution on the profiler callback.  The
  2697         -** sqlite3_profile() function is considered experimental and is
  2698         -** subject to change in future versions of SQLite.
         2700  +** might provide greater resolution on the profiler callback.
         2701  +**
         2702  +** ^The [sqlite3_get_profile(D,X,P)] interface writes into X and P the
         2703  +** values of the profile callback and pointer set by the most recent
         2704  +** [sqlite3_profile()] call on the same [database connection] D.
         2705  +**
         2706  +** All of the tracing and profile interfaces are omitted when the
         2707  +** [SQLITE_OMIT_TRACE] compile-time option is used.
  2699   2708   */
  2700   2709   void *sqlite3_trace(sqlite3*, void(*xTrace)(void*,const char*), void*);
  2701         -SQLITE_EXPERIMENTAL void *sqlite3_profile(sqlite3*,
         2710  +void *sqlite3_profile(sqlite3*,
  2702   2711      void(*xProfile)(void*,const char*,sqlite3_uint64), void*);
         2712  +void sqlite3_get_trace(const sqlite3*, void(**)(void*,const char*),void**);
         2713  +void sqlite3_get_profile(const sqlite3*,
         2714  +   void(**)(void*,const char*,sqlite3_uint64),void**);
  2703   2715   
  2704   2716   /*
  2705   2717   ** CAPI3REF: Query Progress Callbacks
  2706   2718   ** METHOD: sqlite3
  2707   2719   **
  2708   2720   ** ^The sqlite3_progress_handler(D,N,X,P) interface causes the callback
  2709   2721   ** function X to be invoked periodically during long running calls to