Author: timbo
Date: Sun May 13 14:54:00 2007
New Revision: 9564
Modified:
dbi/trunk/Changes
dbi/trunk/DBI.pm
dbi/trunk/DBI.xs
dbi/trunk/lib/DBI/Profile.pm
dbi/trunk/t/40profile.t
Log:
Changed dbi_profile_merge() to dbi_profile_merge_nodes()
old name still works as an alias for the new one.
Modified: dbi/trunk/Changes
==============================================================================
--- dbi/trunk/Changes (original)
+++ dbi/trunk/Changes Sun May 13 14:54:00 2007
@@ -42,6 +42,8 @@
so now in html you get links to individual methods etc.
Changed default gofer retry_limit from 2 to 0.
Changed tests to workaround Math::BigInt broken versions.
+ Changed dbi_profile_merge() to dbi_profile_merge_nodes()
+ old name still works as an alias for the new one.
Added DBI_GOFER_RANDOM env var that can be use to trigger random
failures and delays when executing gofer requests. Designed to help
Modified: dbi/trunk/DBI.pm
==============================================================================
--- dbi/trunk/DBI.pm (original)
+++ dbi/trunk/DBI.pm Sun May 13 14:54:00 2007
@@ -235,7 +235,7 @@
data_string_diff data_string_desc data_diff
) ],
profile => [ qw(
- dbi_profile dbi_profile_merge dbi_time
+ dbi_profile dbi_profile_merge dbi_profile_merge_nodes dbi_time
) ], # notionally "in" DBI::Profile and normally imported from there
);
Modified: dbi/trunk/DBI.xs
==============================================================================
--- dbi/trunk/DBI.xs (original)
+++ dbi/trunk/DBI.xs Sun May 13 14:54:00 2007
@@ -2281,9 +2281,12 @@
node = SvRV(node);
if (SvTYPE(node) != SVt_PVHV) {
HV *hv = newHV();
- if (SvOK(node))
- warn("Profile data element %s replaced with new hash ref (for %s)",
- neatsvpv(orig_node,0), name);
+ if (SvOK(node)) {
+ char *key = "(demoted)";
+ warn("Profile data element %s replaced with new hash ref (for %s)
and original value stored with key '%s'",
+ neatsvpv(orig_node,0), name, key);
+ hv_store(hv, key, strlen(key), SvREFCNT_inc(orig_node), 0);
+ }
sv_setsv(node, newRV_noinc((SV*)hv));
node = (SV*)hv;
}
@@ -2531,7 +2534,7 @@
}
static void
-dbi_profile_merge(SV *dest, SV *increment)
+dbi_profile_merge_nodes(SV *dest, SV *increment)
{
dTHX;
AV *d_av, *i_av;
@@ -2540,7 +2543,7 @@
int i_is_earlier;
if (!SvROK(dest) || SvTYPE(SvRV(dest)) != SVt_PVAV)
- croak("dbi_profile_merge(%s, ...) requires array ref",
neatsvpv(dest,0));
+ croak("dbi_profile_merge_nodes(%s, ...) requires array ref",
neatsvpv(dest,0));
d_av = (AV*)SvRV(dest);
if (av_len(d_av) < DBIprof_max_index) {
@@ -2562,13 +2565,13 @@
I32 keylen = 0;
hv_iterinit(hv);
while ( (tmp = hv_iternextsv(hv, &key, &keylen)) != NULL ) {
- dbi_profile_merge(dest, tmp);
+ dbi_profile_merge_nodes(dest, tmp);
};
return;
}
if (!SvROK(increment) || SvTYPE(SvRV(increment)) != SVt_PVAV)
- croak("dbi_profile_merge: increment not an array or hash ref");
+ croak("dbi_profile_merge_nodes: increment not an array or hash ref");
i_av = (AV*)SvRV(increment);
tmp = *av_fetch(d_av, DBIprof_COUNT, 1);
@@ -4163,12 +4166,14 @@
SV *
-dbi_profile_merge(dest, ...)
+dbi_profile_merge_nodes(dest, ...)
SV * dest
+ ALIAS:
+ dbi_profile_merge = 1
CODE:
{
if (!SvROK(dest) || SvTYPE(SvRV(dest)) != SVt_PVAV)
- croak("dbi_profile_merge(%s,...) not an array reference",
neatsvpv(dest,0));
+ croak("dbi_profile_merge_nodes(%s,...) not an array reference",
neatsvpv(dest,0));
if (items <= 1) {
(void)cv;
RETVAL = 0;
@@ -4177,7 +4182,7 @@
/* items==2 for dest + 1 arg, ST(0) is dest, ST(1) is first arg */
while (--items >= 1) {
SV *thingy = ST(items);
- dbi_profile_merge(dest, thingy);
+ dbi_profile_merge_nodes(dest, thingy);
}
RETVAL = newSVsv(*av_fetch((AV*)SvRV(dest), DBIprof_TOTAL_TIME, 1));
}
Modified: dbi/trunk/lib/DBI/Profile.pm
==============================================================================
--- dbi/trunk/lib/DBI/Profile.pm (original)
+++ dbi/trunk/lib/DBI/Profile.pm Sun May 13 14:54:00 2007
@@ -439,19 +439,19 @@
references or leaf array references.
Sometimes it's useful to be able to summarise some or all of the collected
data.
-The dbi_profile_merge() function can be used to merge leaf node values.
+The dbi_profile_merge_nodes() function can be used to merge leaf node values.
-=head2 dbi_profile_merge
+=head2 dbi_profile_merge_nodes
- use DBI qw(dbi_profile_merge);
+ use DBI qw(dbi_profile_merge_nodes);
- $time_in_dbi = dbi_profile_merge(my $totals=[], @$leaves);
+ $time_in_dbi = dbi_profile_merge_nodes(my $totals=[], @$leaves);
Merges profile data node. Given a reference to a destination array, and zero or
more references to profile data, merges the profile data into the destination
array.
For example:
- $time_in_dbi = dbi_profile_merge(
+ $time_in_dbi = dbi_profile_merge_nodes(
my $totals=[],
[ 10, 0.51, 0.11, 0.01, 0.22, 1023110000, 1023110010 ],
[ 15, 0.42, 0.12, 0.02, 0.23, 1023110005, 1023110009 ],
@@ -463,13 +463,17 @@
and $time_in_dbi will be 0.93;
+The second argument need not be just leaf nodes. If given a reference to a hash
+then the hash is recursively searched for for leaf nodes and all those found
+are merged.
+
For example, to get the time spent 'inside' the DBI during an http request,
your logging code run at the end of the request (i.e. mod_perl LogHandler)
could use:
my $time_in_dbi = 0;
if (my $Profile = $dbh->{Profile}) { # if DBI profiling is enabled
- $time_in_dbi = dbi_profile_merge(my $total=[], $Profile->{Data});
+ $time_in_dbi = dbi_profile_merge_nodes(my $total=[], $Profile->{Data});
$Profile->{Data} = {}; # reset the profile data
}
@@ -477,6 +481,9 @@
the DBI for that handle (and any other handles that share the same profile
data)
since the last request.
+Prior to DBI 1.56 the dbi_profile_merge_nodes() function was called
dbi_profile_merge().
+That name still exists as an alias.
+
=head1 CUSTOM DATA COLLECTION
=head2 Using The Path Attribute
@@ -578,7 +585,7 @@
use UNIVERSAL ();
use Carp;
-use DBI qw(dbi_time dbi_profile dbi_profile_merge);
+use DBI qw(dbi_time dbi_profile dbi_profile_merge_nodes dbi_profile_merge);
$VERSION = sprintf("2.%06d", q$Revision$ =~ /(\d+)/o);
@@ -589,6 +596,7 @@
DBIprofile_MethodName
DBIprofile_MethodClass
dbi_profile
+ dbi_profile_merge_nodes
dbi_profile_merge
dbi_time
);
@@ -674,7 +682,7 @@
)."\n";
if (@$leaves) {
- dbi_profile_merge(my $totals=[], @$leaves);
+ dbi_profile_merge_nodes(my $totals=[], @$leaves);
my ($count, $time_in_dbi, undef, undef, undef, $t1, $t2) = @$totals;
(my $progname = $0) =~ s:.*/::;
if ($count) {
Modified: dbi/trunk/t/40profile.t
==============================================================================
--- dbi/trunk/t/40profile.t (original)
+++ dbi/trunk/t/40profile.t Sun May 13 14:54:00 2007
@@ -325,10 +325,13 @@
'fetchrow_hashref' => [ 1, 0, 0, 0, 0, 0, 0 ],
}, 'should be able to filter by method';
+DBI->trace(0, "STDOUT"); # close current log to flush it
+ok(-s $LOG_FILE, 'output should go to log file');
+
#
-----------------------------------------------------------------------------------
-print "dbi_profile_merge\n";
-my $total_time = dbi_profile_merge(
+print "dbi_profile_merge_nodes\n";
+my $total_time = dbi_profile_merge_nodes(
my $totals=[],
[ 10, 0.51, 0.11, 0.01, 0.22, 1023110000, 1023110010 ],
[ 15, 0.42, 0.12, 0.02, 0.23, 1023110005, 1023110009 ],
@@ -337,7 +340,7 @@
is("@$totals", "25.00 0.93 0.11 0.01 0.23 1023110000.00 1023110010.00");
is($total_time, 0.93);
-$total_time = dbi_profile_merge(
+$total_time = dbi_profile_merge_nodes(
$totals=[], {
foo => [ 10, 1.51, 0.11, 0.01, 0.22, 1023110000, 1023110010 ],
bar => [ 17, 1.42, 0.12, 0.02, 0.23, 1023110005, 1023110009 ],
@@ -347,9 +350,6 @@
is("@$totals", "27.00 2.93 0.11 0.01 0.23 1023110000.00 1023110010.00");
is($total_time, 2.93);
-DBI->trace(0, "STDOUT"); # close current log to flush it
-ok(-s $LOG_FILE, 'output should go to log file');
-
exit 0;