Skip to content

Instantly share code, notes, and snippets.

@churib
Created September 27, 2013 13:29
Show Gist options
  • Save churib/6728594 to your computer and use it in GitHub Desktop.
Save churib/6728594 to your computer and use it in GitHub Desktop.
dbi profiling
$dbh = DBI->connect( $DSN, $DB_USER, $DB_PASS ) || die "cannot connect to database";
$dbh->{HandleError} = sub { confess( shift ) };
$dbh->{Profile} = 31;
$DBI::Profile::ON_DESTROY_DUMP = $DBI::Profile::ON_DESTROY_DUMP = sub {
my ( $result ) = @_;
my $time = $1 if ( $result =~ m/DBI::Profile: ([\d\.]+?)s/ );
return if $time and $time < 0.3;
open my $fh, '>>', '/home/writers/sitedata/logs/db_profile.log';
print $fh shift;
close $fh;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment