Author: timbo
Date: Sat Jul 1 14:01:29 2006
New Revision: 6604
Modified:
dbi/trunk/DBI.pm
dbi/trunk/DBI.xs
dbi/trunk/lib/DBI/Profile.pm
dbi/trunk/t/40profile.t
dbi/trunk/t/72childhandles.t
Log:
Refactor profile code slightly in preparation for code refs in Path
Modified: dbi/trunk/DBI.pm
==============================================================================
--- dbi/trunk/DBI.pm (original)
+++ dbi/trunk/DBI.pm Sat Jul 1 14:01:29 2006
@@ -280,7 +280,7 @@
my $HAS_WEAKEN = eval {
require Scalar::Util;
# this will croak() if this Scalar::Util doesn't have a working weaken().
- Scalar::Util::weaken( \my $test );
+ Scalar::Util::weaken( \my $test ); # same test as in t/72childhandles.t
1;
};
@@ -3342,9 +3342,11 @@
The ChildHandles attribute contains a reference to an array of all the
handles created by this handle which are still accessible. The
contents of the array are weak-refs and will become undef when the
-handle goes out of scope. C<ChildHandles> returns undef if your perl version
-does not support weak references (check the L<Scalar::Util|Scalar::Util>
-module). The referenced array returned should be treated as read-only.
+handle goes out of scope.
+
+C<ChildHandles> returns undef if your perl version does not support weak
+references (check the L<Scalar::Util|Scalar::Util> module). The referenced
+array returned should be treated as read-only.
For example, to enumerate all driver handles, database handles and
statement handles:
Modified: dbi/trunk/DBI.xs
==============================================================================
--- dbi/trunk/DBI.xs (original)
+++ dbi/trunk/DBI.xs Sat Jul 1 14:01:29 2006
@@ -2216,7 +2216,8 @@
dTHX;
double ti = t2 - t1;
const char *path[DBIprof_MAX_PATH_ELEM+1];
- int idx = -1;
+ int src_idx;
+ int dst_idx;
HV *dbh_outer_hv = NULL;
HV *dbh_inner_hv = NULL;
SV *profile;
@@ -2254,9 +2255,9 @@
PerlIO_printf(DBIc_LOGPIO(imp_xxh), "dbi_profile %s %f q{%s}\n",
neatsvpv((SvTYPE(method)==SVt_PVCV) ? (SV*)CvGV(method) :
method, 0),
ti, statement);
-
- idx = 0;
- path[idx++] = "Data";
+ src_idx = 0;
+ dst_idx = 0;
+ path[dst_idx++] = "Data";
tmp = *hv_fetch((HV*)SvRV(profile), "Path", 4, 1);
if (SvROK(tmp) && SvTYPE(SvRV(tmp))==SVt_PVAV) {
@@ -2264,9 +2265,10 @@
av = (AV*)SvRV(tmp);
len = av_len(av); /* -1=empty, 0=one element */
- for ( ;(idx-1) <= len && idx < DBIprof_MAX_PATH_ELEM; ++idx) {
- SV *pathsv = AvARRAY(av)[idx-1];
+ while ( src_idx <= len && dst_idx < DBIprof_MAX_PATH_ELEM) {
+ SV *pathsv = AvARRAY(av)[src_idx++];
const char *p = "?";
+ /* warn("s=%d, d=%d, p=%s", src_idx, dst_idx, neatsvpv(pathsv,0));
*/
if (SvROK(tmp) && SvTYPE(SvRV(tmp))==SVt_PVCV) {
/* call sub, use returned list of values as path */
@@ -2344,17 +2346,17 @@
p = SvPV_nolen(*attr_svp);
}
}
- path[idx] = p;
+ path[dst_idx++] = p;
}
}
else { /* any bad Path value is treated as a Path of just Statement */
- path[idx++] = statement;
+ path[dst_idx++] = statement;
}
- path[idx++] = Nullch;
+ path[dst_idx++] = Nullch;
/* this walk-down-the-tree code should be merged into the loop above */
tmp = profile;
- for (idx=0; path[idx]; ++idx) {
+ for (dst_idx=0; path[dst_idx]; ++dst_idx) {
SV *orig_tmp = tmp;
if (SvROK(tmp))
tmp = SvRV(tmp);
@@ -2365,8 +2367,8 @@
sv_setsv(tmp, newRV_noinc((SV*)hv));
tmp = (SV*)hv;
}
- tmp = *hv_fetch((HV*)tmp, path[idx], strlen(path[idx]), 1);
- /* warn("%d hv_fetch %s = %s", idx, path[idx], neatsvpv(tmp,0)); */
+ tmp = *hv_fetch((HV*)tmp, path[dst_idx], strlen(path[dst_idx]), 1);
+ /* warn("%d hv_fetch %s = %s", dst_idx, path[dst_idx],
neatsvpv(tmp,0)); */
}
if (!SvOK(tmp)) {
av = newAV();
@@ -2384,7 +2386,7 @@
tmp = SvRV(tmp);
if (SvTYPE(tmp) != SVt_PVAV)
croak("Invalid Profile data leaf element at depth %d: %s (type %d)",
- idx, neatsvpv(tmp,0), SvTYPE(tmp));
+ dst_idx, neatsvpv(tmp,0), SvTYPE(tmp));
av = (AV*)tmp;
sv_inc( *av_fetch(av, DBIprof_COUNT, 1));
tmp = *av_fetch(av, DBIprof_TOTAL_TIME, 1);
Modified: dbi/trunk/lib/DBI/Profile.pm
==============================================================================
--- dbi/trunk/lib/DBI/Profile.pm (original)
+++ dbi/trunk/lib/DBI/Profile.pm Sat Jul 1 14:01:29 2006
@@ -645,8 +645,7 @@
1900+$lt[5], $lt[4]+1, @lt[3,2,1,0];
$prologue .= sprintf "(%d calls) $progname \@ $ts\n", $count;
}
-
- if (@$leaves == 1 && $self->{Data}->{DBI}) {
+ if (@$leaves == 1 && ref($self->{Data}) eq 'HASH' &&
$self->{Data}->{DBI}) {
$detail = ""; # hide it
}
}
Modified: dbi/trunk/t/40profile.t
==============================================================================
--- dbi/trunk/t/40profile.t (original)
+++ dbi/trunk/t/40profile.t Sat Jul 1 14:01:29 2006
@@ -27,8 +27,12 @@
# log file to store profile results
my $LOG_FILE = "profile.log";
-DBI->trace(0, $LOG_FILE);
-END { 1 while unlink $LOG_FILE; }
+my $orig_dbi_debug = $DBI::dbi_debug;
+DBI->trace($DBI::dbi_debug, $LOG_FILE);
+END {
+ return if $orig_dbi_debug;
+ 1 while unlink $LOG_FILE;
+}
print "Test enabling the profile\n";
Modified: dbi/trunk/t/72childhandles.t
==============================================================================
--- dbi/trunk/t/72childhandles.t (original)
+++ dbi/trunk/t/72childhandles.t Sat Jul 1 14:01:29 2006
@@ -13,11 +13,12 @@
my $HAS_WEAKEN = eval {
require Scalar::Util;
# this will croak() if this Scalar::Util doesn't have a working weaken().
- Scalar::Util::weaken(my $test = \"foo");
+ Scalar::Util::weaken( \my $test ); # same test as in DBI.pm
1;
};
if (!$HAS_WEAKEN) {
- print "1..0 # Skipped: Scalar::Util::weaken not available\n";
+ chomp $@;
+ print "1..0 # Skipped: Scalar::Util::weaken not available ($@)\n";
exit 0;
}