Author: timbo
Date: Sun Feb  6 04:34:28 2011
New Revision: 14684

Modified:
   dbi/trunk/DBI.xs
   dbi/trunk/DBIXS.h
   dbi/trunk/dbixs_rev.h

Log:
Extend the 'internal method attribute' trace_level mechanism, that was used to
hide calls to low-level methods at low trace levels, so include the concept of
per-method trace flags. If a method has trace flags that are set in the handle
that's calling the method, then set the trace level to at least 2 for the
duration of the call.

I've not writtenm any tests, or even manually tested this code!


Modified: dbi/trunk/DBI.xs
==============================================================================
--- dbi/trunk/DBI.xs    (original)
+++ dbi/trunk/DBI.xs    Sun Feb  6 04:34:28 2011
@@ -99,9 +99,15 @@
     U8 minargs;
     U8 maxargs;
     IV hidearg;
-    IV trace_level;
+    /* method_trace controls tracing of method calls in the dispatcher:
+    - if the current trace flags include a trace flag in method_trace
+    then set trace_level to min(2,trace_level) for duration of the call.
+    - else, if trace_level < (method_trace & DBIc_TRACE_LEVEL_MASK)
+    then don't trace the call
+    */
+    U32 method_trace;
     const char *usage_msg;
-    U32   flags;
+    U32 flags;
 } dbi_ima_t;
 
 /* These values are embedded in the data passed to install_method       */
@@ -3375,8 +3381,13 @@
         if (trace_flags) {
             SAVEI32(DBIS->debug);       /* fall back to orig value later */
             DBIS->debug = trace_flags;  /* make new value global (for now) */
-            if (ima && trace_level < ima->trace_level) {
-                trace_level = 0;        /* silence dispatch log for this 
method */
+            if (ima) {
+                /* enabling trace via flags takes precedence over disabling 
due to min level */
+                if ((trace_flags & DBIc_TRACE_FLAGS_MASK) & (ima->method_trace 
& DBIc_TRACE_FLAGS_MASK))
+                    trace_level = (trace_level < 2) ? 2 : trace_level; /* min 
*/
+                else
+                if (trace_level < (DBIc_TRACE_LEVEL_MASK & ima->method_trace))
+                    trace_level = 0;        /* silence dispatch log for this 
method */
             }
         }
 
@@ -4380,13 +4391,13 @@
         ima = (dbi_ima_t*)(void*)SvPVX(sv);
         memzero((char*)ima, sizeof(*ima));
         DBD_ATTRIB_GET_IV(attribs, "O",1, svp, ima->flags);
-        DBD_ATTRIB_GET_IV(attribs, "T",1, svp, ima->trace_level);
+        DBD_ATTRIB_GET_UV(attribs, "T",1, svp, ima->method_trace);
         DBD_ATTRIB_GET_IV(attribs, "H",1, svp, ima->hidearg);
 
         if (trace_msg) {
             if (ima->flags)       sv_catpvf(trace_msg, ", flags 0x%04x", 
(unsigned)ima->flags);
-            if (ima->trace_level) sv_catpvf(trace_msg, ", T %d", 
(unsigned)ima->trace_level);
-            if (ima->hidearg)     sv_catpvf(trace_msg, ", H %d", 
(unsigned)ima->hidearg);
+            if (ima->method_trace)sv_catpvf(trace_msg, ", T 0x%08lx", 
(unsigned long)ima->method_trace);
+            if (ima->hidearg)     sv_catpvf(trace_msg, ", H %u", 
(unsigned)ima->hidearg);
         }
         if ( (svp=DBD_ATTRIB_GET_SVP(attribs, "U",1)) != NULL) {
             AV *av = (AV*)SvRV(*svp);

Modified: dbi/trunk/DBIXS.h
==============================================================================
--- dbi/trunk/DBIXS.h   (original)
+++ dbi/trunk/DBIXS.h   Sun Feb  6 04:34:28 2011
@@ -197,16 +197,24 @@
 #define DBIc_ACTIVE_KIDS(imp)   _imp2com(imp, std.active_kids)
 #define DBIc_LAST_METHOD(imp)   _imp2com(imp, std.last_method)
 
+/*  d = DBD flags,  l = DBD level (needs to be shifted down)
+ *  D - DBI flags,  r = reserved,  L = DBI trace level
+ *  Trace level bit allocation: 0xddlDDDrL   */
 #define DBIc_TRACE_LEVEL_MASK   0x0000000F
-#define DBIc_TRACE_FLAGS_MASK   0xFFFFFF00
+#define DBIc_TRACE_FLAGS_MASK   0xFF0FFF00  /* includes DBD flag bits for 
DBIc_TRACE */
 #define DBIc_TRACE_SETTINGS(imp) (DBIc_DBISTATE(imp)->debug)
 #define DBIc_TRACE_LEVEL(imp)   (DBIc_TRACE_SETTINGS(imp) & 
DBIc_TRACE_LEVEL_MASK)
 #define DBIc_TRACE_FLAGS(imp)   (DBIc_TRACE_SETTINGS(imp) & 
DBIc_TRACE_FLAGS_MASK)
 /* DBI defined trace flags */
-#define DBIf_TRACE_SQL 0x00000100
-#define DBIf_TRACE_CON 0x00000200
-#define DBIf_TRACE_ENC 0x00000400
-#define DBIf_TRACE_DBD 0x00000800
+#define DBIf_TRACE_SQL          0x00000100
+#define DBIf_TRACE_CON          0x00000200
+#define DBIf_TRACE_ENC          0x00000400
+#define DBIf_TRACE_DBD          0x00000800
+
+#define DBDc_TRACE_LEVEL_MASK   0x00F00000
+#define DBDc_TRACE_LEVEL_SHIFT  20
+#define DBDc_TRACE_LEVEL(imp)         ( (DBIc_TRACE_SETTINGS(imp) & 
DBDc_TRACE_LEVEL_MASK) >> DBDc_TRACE_LEVEL_SHIFT )
+#define DBDc_TRACE_LEVEL_set(imp, l)  ( DBIc_TRACE_SETTINGS(imp) |= (((l) << 
DBDc_TRACE_LEVEL_SHIFT) & DBDc_TRACE_LEVEL_MASK ))
 
 /* DBIc_TRACE_MATCHES(this, crnt): true if this 'matches' (is within) crnt
    DBIc_TRACE_MATCHES(foo, DBIc_TRACE_SETTINGS(imp))
@@ -216,10 +224,10 @@
         || ((crnt & DBIc_TRACE_FLAGS_MASK)  & (this & DBIc_TRACE_FLAGS_MASK)) )
 /* DBIc_TRACE: true if flags match & DBI level>=flaglevel, or if DBI 
level>level
    This is the main trace testing macro to be used by drivers.
-   (Drivers should define their own DBDtf_* macros for the top 8 bits: 
0xFF000000)
-   DBIc_TRACE(imp,         0, 0, 4) = if level >= 4
-   DBIc_TRACE(imp, DBDtf_FOO, 2, 4) = if tracing DBDtf_FOO & level>=2 or 
level>=4
-   DBIc_TRACE(imp, DBDtf_FOO, 2, 0) = as above but never trace just due to 
level
+   (Drivers should define their own DBDf_TRACE_* macros for the top 8 bits: 
0xFF000000)
+   DBIc_TRACE(imp,        0, 0, 4) = if level >= 4
+   DBIc_TRACE(imp, DBDf_FOO, 2, 4) = if tracing DBDf_FOO & level>=2 or level>=4
+   DBIc_TRACE(imp, DBDf_FOO, 2, 0) = as above but never trace just due to level
 */
 #define DBIc_TRACE(imp, flags, flaglevel, level)        \
         (  (flags && (DBIc_TRACE_FLAGS(imp) & flags) && (DBIc_TRACE_LEVEL(imp) 
>= flaglevel)) \

Modified: dbi/trunk/dbixs_rev.h
==============================================================================
--- dbi/trunk/dbixs_rev.h       (original)
+++ dbi/trunk/dbixs_rev.h       Sun Feb  6 04:34:28 2011
@@ -1,4 +1,3 @@
-/* Tue Dec 14 22:26:28 2010 */
-/* Mixed revision working copy (14564M:14571) */
+/* Sun Feb  6 12:26:34 2011 */
 /* Code modified since last checkin */
-#define DBIXS_REVISION 14564
+#define DBIXS_REVISION 14683

Reply via email to