This is the solution I eventually came up with uses callbacks on methods that make a request to the database.
The important clues came from these two notes.
Thanks to everyone for their patient replies!
use strict;
use warnings;
use DBI;
my $dbh = DBI->connect( 'DBI:mysql:database=xxx', 'xxx', 'xxx',
{ RaiseError => 1 } );
my $callback = sub {
return if $_[1] =~ m{ \n-- \s* \S+ .* \n \z }xms;
my $drh = shift @_;
my $new_req = shift @_;
my $method_name = $_;
$new_req =~ s{ ([^\n]) \z }{$1\n}xms;
my $frame_num = 1;
while ( my @frame_info = caller( $frame_num++ ) ) {
$new_req .= "-- $frame_info[3] ($frame_info[1], line $frame_in
+fo[2])\n";
}
undef $_;
return $drh->can( $method_name )->( $drh, $new_req, @_ );
};
my @methods = qw(
do
prepare
prepare_cached
selectrow_array
selectrow_arrayref
selectrow_hashref
selectall_arrayref
selectall_hashref
selectcol_arrayref
);
foreach my $method ( @methods ) {
$dbh->{Callbacks}{$method} = $callback;
}
junker();
sub junker {
for ( 1 .. 1_000_000 ) {
my @junk = $dbh->selectrow_array( 'SELECT 1' );
}
}
__END__
mysql> show processlist;
+----+------+-----------+-------+---------+------+-----------+--------
+------------------------------------------------+
| Id | User | Host | db | Command | Time | State | Info
+ |
+----+------+-----------+-------+---------+------+-----------+--------
+------------------------------------------------+
| 36 | root | localhost | xxxxx | Query | 0 | NULL | show pr
+ocesslist |
| 51 | root | localhost | xxxxx | Query | 0 | executing | SELECT
+1
-- main::junker (/home/kyle/junk.pl, line 45) |
+----+------+-----------+-------+---------+------+-----------+--------
+------------------------------------------------+
2 rows in set (0.00 sec)
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Outside of code tags, you may need to use entities for some characters:
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
|
|