| 1 | package DBIx::Class::QueriesTime; | ||
| 2 | |||
| 3 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 1 | ▶ | use vars qw( $VERSION ); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | |||
| 7 | $VERSION = '0.01'; | ||
| 8 | |||
| 9 | package DBIx::Class::Storage::DBI; | ||
| 10 | 0 | ▶ | use Carp::Clan qw/DBIx::Class/; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 11 | |||
| 12 | use Time::HiRes qw( tv_interval gettimeofday ); | ||
| 13 | no warnings 'redefine'; | ||
| 14 | sub _execute { | ||
| 15 | my ($self, $op, $extra_bind, $ident, @args) = @_; | ||
| 16 | my ($sql, @bind) = $self->sql_maker->$op($ident, @args); | ||
| 17 | unshift(@bind, @$extra_bind) if $extra_bind; | ||
| 18 | if ($self->debug) { | ||
| 19 | my @debug_bind = map { defined $_ ? $_ : 'NULL' } @bind; | ||
| 20 | $self->debugfh->print("$sql: @debug_bind\n"); | ||
| 21 | } | ||
| 22 | my $sth = $self->sth($sql,$op); | ||
| 23 | croak "no sth generated via sql: $sql" unless $sth; | ||
| 24 | @bind = map { ref $_ ? ''.$_ : $_ } @bind; # stringify args | ||
| 25 | my $rv; | ||
| 26 | if ($sth) { | ||
| 27 | my $befor_query = [gettimeofday] if $self->debug; | ||
| 28 | $rv = $sth->execute(@bind); | ||
| 29 | $self->debugfh->print('->Query Time: ',tv_interval($befor_query),"\n") | ||
| 30 | if $self->debug; | ||
| 31 | } else { | ||
| 32 | croak "'$sql' did not generate a statement."; | ||
| 33 | } | ||
| 34 | return (wantarray ? ($rv, $sth, @bind) : $rv); | ||
| 35 | } | ||
| 36 | |||
| 37 | 1; | ||
| 38 | |||
| 39 | =head1 NAME | ||
| 40 | |||
| 41 | DBIx::Class::QueriesTime - Get your query's time. | ||
| 42 | |||
| 43 | =head1 VERSION | ||
| 44 | |||
| 45 | This documentation refers to DBIx::Class::QueriesTime version 0.01 | ||
| 46 | |||
| 47 | =head1 SYNOPSIS | ||
| 48 | |||
| 49 | package YourDB; | ||
| 50 | |||
| 51 | use strict; | ||
| 52 | use warnings; | ||
| 53 | use base 'DBIx::Class'; | ||
| 54 | |||
| 55 | __PACKAGE__->load_components(qw/Core DB QueriesTime/); | ||
| 56 | |||
| 57 | and your script | ||
| 58 | |||
| 59 | #! /usr/bin/perl | ||
| 60 | |||
| 61 | use strict; | ||
| 62 | use warnings; | ||
| 63 | use YourDB; | ||
| 64 | |||
| 65 | YourDB->storage->debug(1); | ||
| 66 | YourDB->storage->debugfh(IO::File->new('/tmp/trace.out', '>>')); | ||
| 67 | |||
| 68 | your query and query's time output trace file: | ||
| 69 | |||
| 70 | SELECT me.id, me.name FROM Authors me WHERE ( name = ? ): nekokak | ||
| 71 | ->Query Time: 0.287087 | ||
| 72 | |||
| 73 | =head1 DESCRIPTION | ||
| 74 | |||
| 75 | DBIx::Class::QueriesTime is Extension to DBIx::Class. | ||
| 76 | DBIx::Class::QueriesTime get your query's time. | ||
| 77 | DBIx::Class::QueriesTime is redefine DBIx::Class::Storage::DBI::_execute. | ||
| 78 | |||
| 79 | =head1 DEPENDENCIES | ||
| 80 | |||
| 81 | L<DBIx::Class> | ||
| 82 | |||
| 83 | L<Time::HiRes> | ||
| 84 | |||
| 85 | =head1 BUGS AND LIMITATIONS | ||
| 86 | |||
| 87 | There are no known bugs in this module. | ||
| 88 | Please report problems to Atsushi Kobayashi (E<lt>nekokak@cpan.orgE<gt>) | ||
| 89 | Patches are welcome. | ||
| 90 | |||
| 91 | =head1 SEE ALSO | ||
| 92 | |||
| 93 | L<DBIx::Class> | ||
| 94 | |||
| 95 | L<Time::HiRes> | ||
| 96 | |||
| 97 | =head1 AUTHOR | ||
| 98 | |||
| 99 | Atsushi Kobayashi, E<lt>nekokak@cpan.orgE<gt> | ||
| 100 | |||
| 101 | =head1 COPYRIGHT AND LICENSE | ||
| 102 | |||
| 103 | Copyright (C) 2006 by Atsushi Kobayashi (E<lt>nekokak@cpan.orgE<gt>). All rights reserved. | ||
| 104 | |||
| 105 | This library is free software; you can redistribute it and/or modify it | ||
| 106 | under the same terms as Perl itself. See L<perlartistic>. | ||
| 107 | |||
| 108 | =cut | ||