Agent/Profile.pm

filter: Statementstmt 27.2% 24 / 88 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 10.7% 3 / 28 Podpod 0.0% 0 / 19 totaltotal 19.7% 27 / 137 CC 4 SCAR 9.3
CC
4
Cov
27%
has_finished
6.0
database_elapsed_time
6.0
webservice_elapsed_time
6.0
CRAP 2.5
« Agent/Frameworks/CGIApplication.pm ↑ Summary Agent/Output/StandardError.pm »
1 # This is a single web request, or a single execution of a script
2  
3 package PerlGuard::Agent::Profile;
4 1 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Time::HiRes;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 has agent => ( is => 'ro', required => 1, weak_ref => 1);
9  
10 1 has uuid => ( is => 'lazy' );
11 1 has start_time => ( is => 'ro' );
12 1 has finish_time => ( is => 'ro' );
13 1 has start_time_hires => ( is => 'ro' );
14 1 has finish_time_hires => ( is => 'ro' );
15  
16 1 has url => ( is => 'rw' );
17 1 has http_method => ( is => 'rw' );
18 1 has controller => ( is => 'rw' );
19 1 has controller_action => ( is => 'rw' );
20 1 has http_code => ( is => 'rw' );
21  
22 0 ▶has should_save => ( is => 'rw', default => sub { 1 } );
Subroutine __ANON__: not called CC=1 SCAR=1.2
23  
24 # has user; # A user definable value
25 # has script_name; # Superceeded by grouping_name which is more generic
26 # has hostname;
27 # has server_name;
28  
29 0 ▶has database_transactions => ( is => 'rw', default => sub {[]});
Subroutine __ANON__: not called CC=1 SCAR=1.2
30 0 ▶has webservice_transactions => ( is => 'rw', default => sub {[]});;
Subroutine __ANON__: not called CC=1 SCAR=1.2
31  
32 0 ▶has cross_application_tracing_id => ( is => 'rw', default => sub { undef });
Subroutine __ANON__: not called CC=1 SCAR=1.2
33  
34 0 ▶sub _build_uuid {
Subroutine _build_uuid: not called CC=1 SCAR=6.9
35 0 my $self = shift;
36  
37 0 return "$self"; # Switch to an actual UUID later
38 }
39  
40 0 ▶sub start_recording {
Subroutine start_recording: not called CC=1 SCAR=6.9
Pod undocumented
41 0 my $self = shift;
42  
43 0 $self->{start_time_hires} = [Time::HiRes::gettimeofday()];
44 0 $self->{start_time} = DateTime->now();
45 }
46  
47 0 ▶sub pause_recording {
Subroutine pause_recording: not called CC=1 SCAR=0.0
Pod undocumented
48  
49 }
50  
51 0 ▶sub finish_recording {
Subroutine finish_recording: not called CC=1 SCAR=6.9
Pod undocumented
52 0 my $self = shift;
53  
54 0 $self->{finish_time_hires} = [Time::HiRes::gettimeofday()];
55 0 $self->{finish_time} = DateTime->now();
56 }
57  
58 0 ▶sub has_finished {
Subroutine has_finished: not called CC=2 SCAR=17.9
Pod undocumented
59 0 my $self = shift;
60  
61 0 ▶ return 1 if defined $self->{finish_time_hires};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"finish_time_hires"} 0 0 0
62 0 return 0;
63 }
64  
65 0 ▶sub save {
Subroutine save: not called CC=1 SCAR=6.9
Pod undocumented
66 0 my $self = shift;
67  
68 0 $self->agent->output->save($self);
69 }
70  
71 0 ▶sub total_elapsed_time {
Subroutine total_elapsed_time: not called CC=1 SCAR=6.9
Pod undocumented
72 0 my $self = shift;
73  
74 0 return Time::HiRes::tv_interval( $self->{start_time_hires}, $self->{finish_time_hires} );
75 }
76  
77 0 ▶sub total_elapsed_time_in_ms {
Subroutine total_elapsed_time_in_ms: not called CC=1 SCAR=6.9
Pod undocumented
78 0 my $self = shift;
79  
80 0 $self->convert_to_ms($self->total_elapsed_time);
81 }
82  
83 0 ▶sub database_transaction_count {
Subroutine database_transaction_count: not called CC=1 SCAR=6.9
Pod undocumented
84 0 my $self = shift;
85  
86 0 scalar(@{$self->database_transactions});
87 }
88  
89 0 ▶sub webservice_transaction_count {
Subroutine webservice_transaction_count: not called CC=1 SCAR=6.9
Pod undocumented
90 0 my $self = shift;
91  
92 0 scalar(@{$self->webservice_transactions});
93 }
94  
95 0 ▶sub database_elapsed_time {
Subroutine database_elapsed_time: not called CC=2 SCAR=17.9
Pod undocumented
96 0 my $self = shift;
97  
98 0 my $total = 0;
99 0 foreach my $database_transaction(@{$self->database_transactions}) {
100  
101 #warn $database_transaction->{start_time};
102  
103 #warn "start " . join(",", @{$database_transaction->{start_time}});
104 #warn "finish " . join(",", @{$database_transaction->{finish_time}});
105 #warn "interval " . Time::HiRes::tv_interval( $database_transaction->{start_time}, $database_transaction->{finish_time});
106  
107 0 $total += Time::HiRes::tv_interval( $database_transaction->{start_time}, $database_transaction->{finish_time});
108 }
109  
110 0 return $total;
111 }
112  
113 0 ▶sub webservice_elapsed_time {
Subroutine webservice_elapsed_time: not called CC=2 SCAR=17.9
Pod undocumented
114 0 my $self = shift;
115  
116 0 my $total = 0;
117 0 foreach my $webservice_transaction(@{$self->webservice_transactions}) {
118 0 $total += Time::HiRes::tv_interval( $webservice_transaction->{start_time}, $webservice_transaction->{finish_time});
119 }
120  
121 0 return $total;
122 }
123  
124 0 ▶sub database_elapsed_time_in_ms {
Subroutine database_elapsed_time_in_ms: not called CC=1 SCAR=6.9
Pod undocumented
125 0 my $self = shift;
126  
127 0 $self->convert_to_ms($self->database_elapsed_time)
128 }
129  
130 0 ▶sub webservice_elapsed_time_in_ms {
Subroutine webservice_elapsed_time_in_ms: not called CC=1 SCAR=6.9
Pod undocumented
131 0 my $self = shift;
132  
133 0 $self->convert_to_ms($self->webservice_elapsed_time)
134 }
135  
136 0 ▶sub add_database_transaction {
Subroutine add_database_transaction: not called CC=1 SCAR=6.9
Pod undocumented
137 0 my $self = shift;
138 0 my $database_transaction = shift;
139  
140 0 push(@{$self->database_transactions}, $database_transaction);
141 }
142  
143 0 ▶sub add_webservice_transaction {
Subroutine add_webservice_transaction: not called CC=1 SCAR=6.9
Pod undocumented
144 0 my $self = shift;
145 0 my $webservice_transaction = shift;
146  
147 0 push(@{$self->webservice_transactions}, $webservice_transaction);
148 }
149  
150 0 ▶sub calculate_time_index_in_ms {
Subroutine calculate_time_index_in_ms: not called CC=1 SCAR=6.9
Pod undocumented
151 0 my $self = shift;
152 0 my $other_time = shift;
153  
154 0 return( $self->convert_to_ms( Time::HiRes::tv_interval($self->{start_time_hires}, $other_time )));
155 }
156  
157 0 ▶sub convert_to_ms {
Subroutine convert_to_ms: not called CC=1 SCAR=6.9
Pod undocumented
158 0 my $self = shift;
159 0 my $thing_to_convert = shift;
160  
161 0 return sprintf("%.0f", $thing_to_convert * 1000)
162 }
163  
164 0 ▶sub do_not_save {
Subroutine do_not_save: not called CC=1 SCAR=6.9
Pod undocumented
165 0 my $self = shift;
166  
167 0 $self->should_save(0);
168 }
169  
170 # Putting the application ID in here would really help the server later on but we aren't requiring the user to specify it yet
171 0 ▶sub generate_new_cross_application_tracing_id {
Subroutine generate_new_cross_application_tracing_id: not called CC=1 SCAR=6.9
Pod undocumented
172 0 my $self = shift;
173  
174 0 return $self->{uuid} . '@' . join(',', (Time::HiRes::gettimeofday()));
175 }
176  
177 0 ▶sub DESTROY {
Subroutine DESTROY: not called CC=1 SCAR=6.9
178 0 my $self = shift;
179  
180 0 $self->agent->output->flush();
181 0 $self->agent->remove_profile($self->uuid);
182 }
183  
184  
185  
186 1 1;
« Agent/Frameworks/CGIApplication.pm ↑ Summary Agent/Output/StandardError.pm »