Filename | /opt/flows/lib/lib/perl5/Search/Elasticsearch/Role/Logger.pm |
Statements | Executed 25 statements in 996µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 2.12ms | 3.44ms | BEGIN@5 | Search::Elasticsearch::Role::Logger::
1 | 1 | 1 | 16µs | 340µs | BEGIN@3 | Search::Elasticsearch::Role::Logger::
1 | 1 | 1 | 12µs | 946µs | trace_request | Search::Elasticsearch::Role::Logger::
1 | 1 | 1 | 12µs | 46µs | trace_response | Search::Elasticsearch::Role::Logger::
1 | 1 | 1 | 10µs | 48µs | BEGIN@6 | Search::Elasticsearch::Role::Logger::
1 | 1 | 1 | 9µs | 147µs | BEGIN@7 | Search::Elasticsearch::Role::Logger::
1 | 1 | 1 | 9µs | 264µs | BEGIN@8 | Search::Elasticsearch::Role::Logger::
1 | 1 | 1 | 7µs | 43µs | __ANON__[:3] | Search::Elasticsearch::Role::Logger::
1 | 1 | 1 | 2µs | 2µs | trace_to (xsub) | Search::Elasticsearch::Role::Logger::
1 | 1 | 1 | 1µs | 1µs | trace_as (xsub) | Search::Elasticsearch::Role::Logger::
1 | 1 | 1 | 1µs | 1µs | log_to (xsub) | Search::Elasticsearch::Role::Logger::
1 | 1 | 1 | 800ns | 800ns | log_as (xsub) | Search::Elasticsearch::Role::Logger::
0 | 0 | 0 | 0s | 0s | throw_critical | Search::Elasticsearch::Role::Logger::
0 | 0 | 0 | 0s | 0s | throw_error | Search::Elasticsearch::Role::Logger::
0 | 0 | 0 | 0s | 0s | trace_comment | Search::Elasticsearch::Role::Logger::
0 | 0 | 0 | 0s | 0s | trace_error | Search::Elasticsearch::Role::Logger::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Search::Elasticsearch::Role::Logger; | ||||
2 | 1 | 500ns | $Search::Elasticsearch::Role::Logger::VERSION = '2.02'; | ||
3 | 4 | 44µs | 3 | 701µs | # spent 340µs (16+324) within Search::Elasticsearch::Role::Logger::BEGIN@3 which was called:
# once (16µs+324µs) by Module::Runtime::require_module at line 3
# spent 43µs (7+36) within Search::Elasticsearch::Role::Logger::__ANON__[/opt/flows/lib/lib/perl5/Search/Elasticsearch/Role/Logger.pm:3] which was called:
# once (7µs+36µs) by import::into at line 34 of Import/Into.pm # spent 340µs making 1 call to Search::Elasticsearch::Role::Logger::BEGIN@3
# spent 324µs making 1 call to Moo::Role::import
# spent 36µs making 1 call to strictures::import |
4 | |||||
5 | 2 | 126µs | 1 | 3.44ms | # spent 3.44ms (2.12+1.31) within Search::Elasticsearch::Role::Logger::BEGIN@5 which was called:
# once (2.12ms+1.31ms) by Module::Runtime::require_module at line 5 # spent 3.44ms making 1 call to Search::Elasticsearch::Role::Logger::BEGIN@5 |
6 | 2 | 44µs | 2 | 87µs | # spent 48µs (10+39) within Search::Elasticsearch::Role::Logger::BEGIN@6 which was called:
# once (10µs+39µs) by Module::Runtime::require_module at line 6 # spent 48µs making 1 call to Search::Elasticsearch::Role::Logger::BEGIN@6
# spent 39µs making 1 call to Exporter::import |
7 | 2 | 37µs | 2 | 285µs | # spent 147µs (9+138) within Search::Elasticsearch::Role::Logger::BEGIN@7 which was called:
# once (9µs+138µs) by Module::Runtime::require_module at line 7 # spent 147µs making 1 call to Search::Elasticsearch::Role::Logger::BEGIN@7
# spent 138µs making 1 call to Sub::Exporter::__ANON__[/opt/flows/lib/lib/perl5/Sub/Exporter.pm:337] |
8 | 2 | 687µs | 2 | 519µs | # spent 264µs (9+255) within Search::Elasticsearch::Role::Logger::BEGIN@8 which was called:
# once (9µs+255µs) by Module::Runtime::require_module at line 8 # spent 264µs making 1 call to Search::Elasticsearch::Role::Logger::BEGIN@8
# spent 255µs making 1 call to namespace::clean::import |
9 | |||||
10 | 1 | 2µs | 1 | 140µs | has 'serializer' => ( is => 'ro', required => 1 ); # spent 140µs making 1 call to Moo::Role::has |
11 | 1 | 1µs | 1 | 112µs | has 'log_as' => ( is => 'ro', default => 'elasticsearch.event' ); # spent 112µs making 1 call to Moo::Role::has |
12 | 1 | 1µs | 1 | 111µs | has 'trace_as' => ( is => 'ro', default => 'elasticsearch.trace' ); # spent 111µs making 1 call to Moo::Role::has |
13 | 1 | 1µs | 1 | 119µs | has 'log_to' => ( is => 'ro' ); # spent 119µs making 1 call to Moo::Role::has |
14 | 1 | 1µs | 1 | 111µs | has 'trace_to' => ( is => 'ro' ); # spent 111µs making 1 call to Moo::Role::has |
15 | 1 | 2µs | 1 | 560µs | has 'trace_handle' => ( # spent 560µs making 1 call to Moo::Role::has |
16 | is => 'lazy', | ||||
17 | handles => [qw( trace tracef is_trace)] | ||||
18 | ); | ||||
19 | |||||
20 | 1 | 4µs | 1 | 1.30ms | has 'log_handle' => ( # spent 1.30ms making 1 call to Moo::Role::has |
21 | is => 'lazy', | ||||
22 | handles => [ qw( | ||||
23 | debug debugf is_debug | ||||
24 | info infof is_info | ||||
25 | warning warningf is_warning | ||||
26 | error errorf is_error | ||||
27 | critical criticalf is_critical | ||||
28 | ) | ||||
29 | ] | ||||
30 | ); | ||||
31 | |||||
32 | #=================================== | ||||
33 | sub throw_error { | ||||
34 | #=================================== | ||||
35 | my ( $self, $type, $msg, $vars ) = @_; | ||||
36 | my $error = new_error( $type, $msg, $vars ); | ||||
37 | $self->error($error); | ||||
38 | die $error; | ||||
39 | } | ||||
40 | |||||
41 | #=================================== | ||||
42 | sub throw_critical { | ||||
43 | #=================================== | ||||
44 | my ( $self, $type, $msg, $vars ) = @_; | ||||
45 | my $error = new_error( $type, $msg, $vars ); | ||||
46 | $self->critical($error); | ||||
47 | die $error; | ||||
48 | } | ||||
49 | |||||
50 | #=================================== | ||||
51 | # spent 946µs (12+934) within Search::Elasticsearch::Role::Logger::trace_request which was called:
# once (12µs+934µs) by Search::Elasticsearch::Transport::try {...} at line 27 of /opt/flows/lib/lib/perl5/Search/Elasticsearch/Transport.pm | ||||
52 | #=================================== | ||||
53 | 1 | 800ns | my ( $self, $cxn, $params ) = @_; | ||
54 | 1 | 7µs | 1 | 377µs | return unless $self->is_trace; # spent 377µs making 1 call to Search::Elasticsearch::Role::Logger::is_trace |
55 | |||||
56 | my $uri = URI->new( 'http://localhost:9200' . $params->{path} ); | ||||
57 | my %qs = ( %{ $params->{qs} }, pretty => 1 ); | ||||
58 | $uri->query_form( [ map { $_, $qs{$_} } sort keys %qs ] ); | ||||
59 | |||||
60 | my $body | ||||
61 | = $params->{serialize} eq 'std' | ||||
62 | ? $self->serializer->encode_pretty( $params->{body} ) | ||||
63 | : $params->{data}; | ||||
64 | |||||
65 | if ( defined $body ) { | ||||
66 | $body =~ s/'/\\u0027/g; | ||||
67 | $body = " -d '\n$body'\n"; | ||||
68 | } | ||||
69 | else { $body = "\n" } | ||||
70 | |||||
71 | my $msg = sprintf( | ||||
72 | "# Request to: %s\n" # | ||||
73 | . "curl -X%s '%s'%s", # | ||||
74 | $cxn->stringify, | ||||
75 | $params->{method}, | ||||
76 | $uri, | ||||
77 | $body | ||||
78 | ); | ||||
79 | |||||
80 | $self->trace($msg); | ||||
81 | } | ||||
82 | |||||
83 | #=================================== | ||||
84 | # spent 46µs (12+34) within Search::Elasticsearch::Role::Logger::trace_response which was called:
# once (12µs+34µs) by Search::Elasticsearch::Transport::try {...} at line 31 of /opt/flows/lib/lib/perl5/Search/Elasticsearch/Transport.pm | ||||
85 | #=================================== | ||||
86 | 1 | 1µs | my ( $self, $cxn, $code, $response, $took ) = @_; | ||
87 | 1 | 6µs | 1 | 3µs | return unless $self->is_trace; # spent 3µs making 1 call to Search::Elasticsearch::Role::Logger::is_trace |
88 | |||||
89 | my $body = $self->serializer->encode_pretty($response) || "\n"; | ||||
90 | $body =~ s/^/# /mg; | ||||
91 | |||||
92 | my $msg = sprintf( | ||||
93 | "# Response: %s, Took: %d ms\n%s", # | ||||
94 | $code, $took * 1000, $body | ||||
95 | ); | ||||
96 | |||||
97 | $self->trace($msg); | ||||
98 | } | ||||
99 | |||||
100 | #=================================== | ||||
101 | sub trace_error { | ||||
102 | #=================================== | ||||
103 | my ( $self, $cxn, $error ) = @_; | ||||
104 | return unless $self->is_trace; | ||||
105 | |||||
106 | my $body | ||||
107 | = $self->serializer->encode_pretty( $error->{vars}{body} || "\n" ); | ||||
108 | $body =~ s/^/# /mg; | ||||
109 | |||||
110 | my $msg | ||||
111 | = sprintf( "# ERROR: %s %s\n%s", ref($error), $error->{text}, $body ); | ||||
112 | |||||
113 | $self->trace($msg); | ||||
114 | } | ||||
115 | |||||
116 | #=================================== | ||||
117 | sub trace_comment { | ||||
118 | #=================================== | ||||
119 | my ( $self, $comment ) = @_; | ||||
120 | return unless $self->is_trace; | ||||
121 | $comment =~ s/^/# *** /mg; | ||||
122 | chomp $comment; | ||||
123 | $self->trace("$comment\n"); | ||||
124 | } | ||||
125 | |||||
126 | 1 | 12µs | 1; | ||
127 | |||||
128 | # ABSTRACT: Provides common functionality to Logger implementations | ||||
129 | |||||
130 | 1 | 18µs | 1 | 451µs | __END__ # spent 451µs making 1 call to B::Hooks::EndOfScope::XS::__ANON__[/opt/flows/lib/lib/perl5/B/Hooks/EndOfScope/XS.pm:17] |
# spent 800ns within Search::Elasticsearch::Role::Logger::log_as which was called:
# once (800ns+0s) by Search::Elasticsearch::Logger::LogAny::_build_log_handle at line 18 of /opt/flows/lib/lib/perl5/Search/Elasticsearch/Logger/LogAny.pm | |||||
# spent 1µs within Search::Elasticsearch::Role::Logger::log_to which was called:
# once (1µs+0s) by Search::Elasticsearch::Logger::LogAny::_build_log_handle at line 15 of /opt/flows/lib/lib/perl5/Search/Elasticsearch/Logger/LogAny.pm | |||||
# spent 1µs within Search::Elasticsearch::Role::Logger::trace_as which was called:
# once (1µs+0s) by Search::Elasticsearch::Logger::LogAny::_build_trace_handle at line 28 of /opt/flows/lib/lib/perl5/Search/Elasticsearch/Logger/LogAny.pm | |||||
# spent 2µs within Search::Elasticsearch::Role::Logger::trace_to which was called:
# once (2µs+0s) by Search::Elasticsearch::Logger::LogAny::_build_trace_handle at line 25 of /opt/flows/lib/lib/perl5/Search/Elasticsearch/Logger/LogAny.pm |