Stats/Profiler.pm

filter: Statementstmt 100% 24 / 24 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 85.7% 6 / 7 Podpod 100% 3 / 3 totaltotal 97.0% 33 / 34 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« Stats.pm ↑ Summary
1 package Test::DBIx::Class::Stats::Profiler;
2 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use MooX::HandlesVia;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Time::HiRes;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 our $VERSION = 0.02;
7  
8 =head1 NAME
9  
10 Test::DBIC::Profiler - a simple DBIC profiler
11  
12 =head1 SYNOPSIS
13  
14 See L<Test::DBIC::Calls> for how to use.
15 This class extends L<DBIx::Class::Storage::Statistics> and could
16 alternatively be used as per that class.
17  
18 =head1 METHODS
19  
20 =over 4
21  
22 =item C<call_count>
23  
24 Returns the number of calls made to the database.
25  
26 =item C<all_calls>
27  
28 Returns a list of calls made, as an array of hashes:
29  
30 [ { sql => ..., params => [...], elapsed => ... }, ... ]
31  
32 =back
33  
34 =cut
35  
36 1 extends 'DBIx::Class::Storage::Statistics';
37  
38 1 has start => (
39 is => 'rw',
40 );
41  
42 has calls => (
43 is => 'lazy',
44 2 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
45 1 handles_via => 'Array',
46 handles => {
47 all_calls => 'elements',
48 add_call => 'push',
49 call_count => 'count',
50 },
51 );
52  
53 0 ▶sub print { } # silence logging
Subroutine print: not called CC=1 SCAR=0.0
Pod documented
54  
55 5 ▶sub query_start {
Subroutine query_start: called CC=1 SCAR=0.0
Pod documented
56 5 my $self = shift();
57 5 my $sql = shift();
58 5 my @params = @_;
59  
60 5 $self->start( time() );
61 }
62
63 5 ▶sub query_end {
Subroutine query_end: called CC=1 SCAR=0.0
Pod documented
64 5 my $self = shift();
65 5 my $sql = shift();
66 5 my @params = @_;
67
68 5 my $elapsed = time() - $self->start;
69  
70 5 $self->add_call({
71 sql => $sql,
72 params => \@params,
73 elapsed => $elapsed
74 });
75 }
76  
77 =head1 AUTHOR
78  
79 osfameron <osfameron@cpan.org> 2014-2017
80 Alexander Hartmaier <abraxxa@cpan.org> 2017
81  
82 =cut
83  
84 1 1;
« Stats.pm ↑ Summary