Author: timbo
Date: Tue Mar  9 06:35:09 2004
New Revision: 205

Modified:
   dbi/trunk/DBI.xs
   dbi/trunk/DBIXS.h
   dbi/trunk/dbivport.h
   dbi/trunk/lib/DBD/Multiplex.pm
Log:
More work on tracing. Good enough for release.


Modified: dbi/trunk/DBI.xs
==============================================================================
--- dbi/trunk/DBI.xs    (original)
+++ dbi/trunk/DBI.xs    Tue Mar  9 06:35:09 2004
@@ -3539,7 +3539,8 @@
        ix=ix;          /* avoid 'unused variable' warnings     */
        croak("DBI not initialised");
     }
-    set_trace_file(file);      /* always call this regardless of level */
+    if (level)         /* call before or after altering DBI trace level */
+        set_trace_file(file);
     if (level != RETVAL) {
        if ((level & DBIc_TRACE_LEVEL_MASK) > 0) {
            PerlIO_printf(DBILOGFP,"    DBI %s%s default trace level set to Ox%lx/%ld 
(in pid %d)\n",
@@ -3554,6 +3555,8 @@
        DBIS->debug = level;
        sv_setiv(perl_get_sv("DBI::dbi_debug",0x5), level);
     }
+    if (!level)                /* call before or after altering DBI trace level */
+        set_trace_file(file);
     }
     OUTPUT:
     RETVAL
@@ -4080,21 +4083,27 @@
 
 
 void
-trace_msg(sv, msg, min_level=1)
+trace_msg(sv, msg, this_trace=1)
     SV *sv
     char *msg
-    int min_level
+    int this_trace
     PREINIT:
-    int debug = 0;
+    int current_trace;
+    PerlIO *pio;
     CODE:
     {
     dPERINTERP;
     if (SvROK(sv)) {
        D_imp_xxh(sv);
-       debug = DBIc_TRACE_LEVEL(imp_xxh);
+       current_trace = DBIc_TRACE_LEVEL(imp_xxh);
+       pio = DBIc_LOGPIO(imp_xxh);
     }
-    if (DBIS_TRACE_LEVEL >= min_level || debug >= min_level) {
-       PerlIO_puts(DBILOGFP, msg);
+    else {     /* called as a static method */
+       current_trace = DBIS_TRACE_FLAGS;
+       pio = DBILOGFP;
+    }
+    if (DBIc_TRACE_MATCHES(this_trace, current_trace)) {
+       PerlIO_puts(pio, msg);
         ST(0) = &sv_yes;
     }
     else {

Modified: dbi/trunk/DBIXS.h
==============================================================================
--- dbi/trunk/DBIXS.h   (original)
+++ dbi/trunk/DBIXS.h   Tue Mar  9 06:35:09 2004
@@ -199,13 +199,27 @@
 #define DBIc_LAST_METHOD(imp)          _imp2com(imp, std.last_method)
 
 #define DBIc_TRACE_LEVEL_MASK  0x0000000F
-#define DBIc_TRACE_TOPIC_MASK  0x00FFFF00
-#define DBDc_TRACE_TOPIC_MASK  0xFF000000
-#define DBIc_TRACE_LEVEL(imp)  (DBIc_DBISTATE(imp)->debug &  DBIc_TRACE_LEVEL_MASK)
-#define DBIc_TRACE_FLAGS(imp)  (DBIc_DBISTATE(imp)->debug & ~DBIc_TRACE_LEVEL_MASK)
+#define DBIc_TRACE_FLAGS_MASK  0xFFFFFF00
+#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)
+/* DBIc_TRACE_MATCHES(this, crnt): true if this 'matches' (is within) crnt
+   DBIc_TRACE_MATCHES(foo, DBIc_TRACE_SETTINGS(imp))
+*/
+#define DBIc_TRACE_MATCHES(this, crnt) \
+       (  ((crnt & DBIc_TRACE_LEVEL_MASK) >= (this & DBIc_TRACE_LEVEL_MASK)) \
+       || ((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
+*/
 #define DBIc_TRACE(imp, flags, flaglevel, level)       \
        (  (flags && (DBIc_TRACE_FLAGS(imp) & flags) && (DBIc_TRACE_LEVEL(imp) >= 
flaglevel)) \
        || (level && DBIc_TRACE_LEVEL(imp) >= level) )
+
 #define DBIc_DEBUG(imp)                (_imp2com(imp, attr.TraceLevel)) /* deprecated 
*/
 #define DBIc_DEBUGIV(imp)      SvIV(DBIc_DEBUG(imp))            /* deprecated */
 #define DBIc_STATE(imp)                SvRV(_imp2com(imp, attr.State))

Modified: dbi/trunk/dbivport.h
==============================================================================
--- dbi/trunk/dbivport.h        (original)
+++ dbi/trunk/dbivport.h        Tue Mar  9 06:35:09 2004
@@ -22,12 +22,23 @@
         sv_setpv(DBIc_ERRSTR(imp_xxh), errstr)
 #endif
 
-#ifndef DBIc_TRACE
+#ifndef DBIc_TRACE_LEVEL_MASK
 #define DBIc_TRACE_LEVEL_MASK   0x0000000F
-#define DBIc_TRACE_TOPIC_MASK   0x00FFFF00
-#define DBDc_TRACE_TOPIC_MASK   0xFF000000
-#define DBIc_TRACE_LEVEL(imp)   (DBIc_DBISTATE(imp)->debug &  DBIc_TRACE_LEVEL_MASK)
-#define DBIc_TRACE_FLAGS(imp)   (DBIc_DBISTATE(imp)->debug & ~DBIc_TRACE_LEVEL_MASK)
+#define DBIc_TRACE_FLAGS_MASK   0xFFFFFF00
+#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)
+/* DBIc_TRACE_MATCHES - true if s1 'matches' s2  (c.f. trace_msg())
+   DBIc_TRACE_MATCHES(foo, DBIc_TRACE_SETTINGS(imp))
+*/
+#define DBIc_TRACE_MATCHES(s1, s2)      \
+        (  ((s1 & DBIc_TRACE_LEVEL_MASK) >= (s2 & DBIc_TRACE_LEVEL_MASK)) \
+        || ((s1 & DBIc_TRACE_FLAGS_MASK)  & (s2 & DBIc_TRACE_FLAGS_MASK)) )
+/* DBIc_TRACE - true if flags match & DBI level>=flaglevel, or if DBI level>level
+   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
+*/
 #define DBIc_TRACE(imp, flags, flaglevel, level)        \
         (  (flags && (DBIc_TRACE_FLAGS(imp) & flags) && (DBIc_TRACE_LEVEL(imp) >= 
flaglevel)) \
         || (level && DBIc_TRACE_LEVEL(imp) >= level) )

Modified: dbi/trunk/lib/DBD/Multiplex.pm
==============================================================================
--- dbi/trunk/lib/DBD/Multiplex.pm      (original)
+++ dbi/trunk/lib/DBD/Multiplex.pm      Tue Mar  9 06:35:09 2004
@@ -313,7 +313,7 @@
     push @dsn_list, @{ delete $attr->{mx_dsns} }  if $attr->{mx_dsns};

     push @dsn_list, @dsn_list                     if $attr->{mx_double};

     push @dsn_list, @dsn_list, @dsn_list          if $attr->{mx_triple};

-    return DBI::set_err($drh, 1, "No dsn given") unless @dsn_list;

+    return $drh->set_err(1, "No dsn given") unless @dsn_list;

     my @orig_dsn_list = @dsn_list; # @dsn_list gets edited below

 

     # exit_mode decides when to exit the foreach loop.

Reply via email to