Filename | /opt/flows/lib/lib/perl5/Log/Any/Adapter/Util.pm |
Statements | Executed 82 statements in 1.24ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
2 | 1 | 1 | 1.09ms | 1.23ms | require_dynamic | Log::Any::Adapter::Util::
14 | 1 | 1 | 25µs | 25µs | numeric_level | Log::Any::Adapter::Util::
1 | 1 | 1 | 21µs | 21µs | BEGIN@52 | Log::Any::Adapter::Util::
1 | 1 | 1 | 19µs | 19µs | BEGIN@1.7 | Log::Any::
1 | 1 | 1 | 11µs | 23µs | BEGIN@151 | Log::Any::Adapter::Util::
1 | 1 | 1 | 10µs | 28µs | BEGIN@10 | Log::Any::Adapter::Util::
1 | 1 | 1 | 9µs | 21µs | BEGIN@167 | Log::Any::Adapter::Util::
1 | 1 | 1 | 8µs | 125µs | BEGIN@28 | Log::Any::Adapter::Util::
2 | 2 | 2 | 8µs | 8µs | logging_and_detection_methods | Log::Any::Adapter::Util::
1 | 1 | 1 | 8µs | 13µs | BEGIN@3.9 | Log::Any::
1 | 1 | 1 | 8µs | 8µs | BEGIN@14 | Log::Any::Adapter::Util::
1 | 1 | 1 | 8µs | 21µs | BEGIN@2.8 | Log::Any::
1 | 1 | 1 | 4µs | 4µs | log_level_aliases | Log::Any::Adapter::Util::
1 | 1 | 1 | 2µs | 2µs | logging_methods | Log::Any::Adapter::Util::
0 | 0 | 0 | 0s | 0s | __ANON__[:148] | Log::Any::Adapter::Util::
0 | 0 | 0 | 0s | 0s | __ANON__[:154] | Log::Any::Adapter::Util::
0 | 0 | 0 | 0s | 0s | cmp_deeply | Log::Any::Adapter::Util::
0 | 0 | 0 | 0s | 0s | detection_aliases | Log::Any::Adapter::Util::
0 | 0 | 0 | 0s | 0s | detection_methods | Log::Any::Adapter::Util::
0 | 0 | 0 | 0s | 0s | logging_aliases | Log::Any::Adapter::Util::
0 | 0 | 0 | 0s | 0s | make_method | Log::Any::Adapter::Util::
0 | 0 | 0 | 0s | 0s | read_file | Log::Any::Adapter::Util::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | 2 | 51µs | 1 | 19µs | # spent 19µs within Log::Any::BEGIN@1.7 which was called:
# once (19µs+0s) by Log::Any::BEGIN@11 at line 1 # spent 19µs making 1 call to Log::Any::BEGIN@1.7 |
2 | 2 | 26µs | 2 | 35µs | # spent 21µs (8+14) within Log::Any::BEGIN@2.8 which was called:
# once (8µs+14µs) by Log::Any::BEGIN@11 at line 2 # spent 21µs making 1 call to Log::Any::BEGIN@2.8
# spent 14µs making 1 call to strict::import |
3 | 2 | 52µs | 2 | 18µs | # spent 13µs (8+5) within Log::Any::BEGIN@3.9 which was called:
# once (8µs+5µs) by Log::Any::BEGIN@11 at line 3 # spent 13µs making 1 call to Log::Any::BEGIN@3.9
# spent 5µs making 1 call to warnings::import |
4 | |||||
5 | package Log::Any::Adapter::Util; | ||||
6 | |||||
7 | # ABSTRACT: Common utility functions for Log::Any | ||||
8 | 1 | 700ns | our $VERSION = '1.040'; | ||
9 | |||||
10 | 2 | 74µs | 2 | 46µs | # spent 28µs (10+18) within Log::Any::Adapter::Util::BEGIN@10 which was called:
# once (10µs+18µs) by Log::Any::BEGIN@11 at line 10 # spent 28µs making 1 call to Log::Any::Adapter::Util::BEGIN@10
# spent 18µs making 1 call to Exporter::import |
11 | 1 | 6µs | our @ISA = qw/Exporter/; | ||
12 | |||||
13 | 1 | 200ns | my %LOG_LEVELS; | ||
14 | # spent 8µs within Log::Any::Adapter::Util::BEGIN@14 which was called:
# once (8µs+0s) by Log::Any::BEGIN@11 at line 26 | ||||
15 | 1 | 8µs | %LOG_LEVELS = ( | ||
16 | EMERGENCY => 0, | ||||
17 | ALERT => 1, | ||||
18 | CRITICAL => 2, | ||||
19 | ERROR => 3, | ||||
20 | WARNING => 4, | ||||
21 | NOTICE => 5, | ||||
22 | INFO => 6, | ||||
23 | DEBUG => 7, | ||||
24 | TRACE => 8, | ||||
25 | ); | ||||
26 | 1 | 28µs | 1 | 8µs | } # spent 8µs making 1 call to Log::Any::Adapter::Util::BEGIN@14 |
27 | |||||
28 | 2 | 179µs | 2 | 241µs | # spent 125µs (8+116) within Log::Any::Adapter::Util::BEGIN@28 which was called:
# once (8µs+116µs) by Log::Any::BEGIN@11 at line 28 # spent 125µs making 1 call to Log::Any::Adapter::Util::BEGIN@28
# spent 116µs making 1 call to constant::import |
29 | |||||
30 | 1 | 2µs | our @EXPORT_OK = qw( | ||
31 | cmp_deeply | ||||
32 | detection_aliases | ||||
33 | detection_methods | ||||
34 | dump_one_line | ||||
35 | log_level_aliases | ||||
36 | logging_aliases | ||||
37 | logging_and_detection_methods | ||||
38 | logging_methods | ||||
39 | make_method | ||||
40 | numeric_level | ||||
41 | read_file | ||||
42 | require_dynamic | ||||
43 | ); | ||||
44 | |||||
45 | 1 | 3µs | push @EXPORT_OK, keys %LOG_LEVELS; | ||
46 | |||||
47 | 1 | 3µs | our %EXPORT_TAGS = ( 'levels' => [ keys %LOG_LEVELS ] ); | ||
48 | |||||
49 | 1 | 100ns | my ( %LOG_LEVEL_ALIASES, @logging_methods, @logging_aliases, @detection_methods, | ||
50 | @detection_aliases, @logging_and_detection_methods ); | ||||
51 | |||||
52 | # spent 21µs within Log::Any::Adapter::Util::BEGIN@52 which was called:
# once (21µs+0s) by Log::Any::BEGIN@11 at line 66 | ||||
53 | 1 | 4µs | %LOG_LEVEL_ALIASES = ( | ||
54 | inform => 'info', | ||||
55 | warn => 'warning', | ||||
56 | err => 'error', | ||||
57 | crit => 'critical', | ||||
58 | fatal => 'critical' | ||||
59 | ); | ||||
60 | 1 | 2µs | @logging_methods = | ||
61 | qw(trace debug info notice warning error critical alert emergency); | ||||
62 | 1 | 2µs | @logging_aliases = keys(%LOG_LEVEL_ALIASES); | ||
63 | 1 | 5µs | @detection_methods = map { "is_$_" } @logging_methods; | ||
64 | 1 | 2µs | @detection_aliases = map { "is_$_" } @logging_aliases; | ||
65 | 1 | 8µs | @logging_and_detection_methods = ( @logging_methods, @detection_methods ); | ||
66 | 1 | 292µs | 1 | 21µs | } # spent 21µs making 1 call to Log::Any::Adapter::Util::BEGIN@52 |
67 | |||||
68 | #pod =func logging_methods | ||||
69 | #pod | ||||
70 | #pod Returns a list of all logging method. E.g. "trace", "info", etc. | ||||
71 | #pod | ||||
72 | #pod =cut | ||||
73 | |||||
74 | 1 | 4µs | # spent 2µs within Log::Any::Adapter::Util::logging_methods which was called:
# once (2µs+0s) by Log::Any::Adapter::Util::require_dynamic at line 50 of /opt/flows/lib/lib/perl5/Log/Any/Proxy.pm | ||
75 | |||||
76 | #pod =func detection_methods | ||||
77 | #pod | ||||
78 | #pod Returns a list of detection methods. E.g. "is_trace", "is_info", etc. | ||||
79 | #pod | ||||
80 | #pod =cut | ||||
81 | |||||
82 | sub detection_methods { @detection_methods } | ||||
83 | |||||
84 | #pod =func logging_and_detection_methods | ||||
85 | #pod | ||||
86 | #pod Returns a list of logging and detection methods (but not aliases). | ||||
87 | #pod | ||||
88 | #pod =cut | ||||
89 | |||||
90 | 2 | 16µs | # spent 8µs within Log::Any::Adapter::Util::logging_and_detection_methods which was called 2 times, avg 4µs/call:
# once (4µs+0s) by Log::Any::Adapter::Null::BEGIN@10 at line 23 of /opt/flows/lib/lib/perl5/Log/Any/Adapter/Base.pm
# once (4µs+0s) by Log::Any::Manager::_require_dynamic at line 17 of /opt/flows/lib/lib/perl5/Log/Any/Adapter/Null.pm | ||
91 | |||||
92 | #pod =func log_level_aliases | ||||
93 | #pod | ||||
94 | #pod Returns key/value pairs mapping aliases to "official" names. E.g. "err" maps | ||||
95 | #pod to "error". | ||||
96 | #pod | ||||
97 | #pod =cut | ||||
98 | |||||
99 | 1 | 8µs | # spent 4µs within Log::Any::Adapter::Util::log_level_aliases which was called:
# once (4µs+0s) by Log::Any::Adapter::Util::require_dynamic at line 47 of /opt/flows/lib/lib/perl5/Log/Any/Proxy.pm | ||
100 | |||||
101 | #pod =func logging_aliases | ||||
102 | #pod | ||||
103 | #pod Returns a list of logging alias names. These are the keys from | ||||
104 | #pod L</log_level_aliases>. | ||||
105 | #pod | ||||
106 | #pod =cut | ||||
107 | |||||
108 | sub logging_aliases { @logging_aliases } | ||||
109 | |||||
110 | #pod =func detection_aliases | ||||
111 | #pod | ||||
112 | #pod Returns a list of detection aliases. E.g. "is_err", "is_fatal", etc. | ||||
113 | #pod | ||||
114 | #pod =cut | ||||
115 | |||||
116 | sub detection_aliases { @detection_aliases } | ||||
117 | |||||
118 | #pod =func numeric_level | ||||
119 | #pod | ||||
120 | #pod Given a level name (or alias), returns the numeric value described above under | ||||
121 | #pod log level constants. E.g. "err" would return 3. | ||||
122 | #pod | ||||
123 | #pod =cut | ||||
124 | |||||
125 | # spent 25µs within Log::Any::Adapter::Util::numeric_level which was called 14 times, avg 2µs/call:
# 14 times (25µs+0s) by Log::Any::Adapter::Util::require_dynamic at line 56 of /opt/flows/lib/lib/perl5/Log/Any/Proxy.pm, avg 2µs/call | ||||
126 | 14 | 3µs | my ($level) = @_; | ||
127 | 14 | 5µs | my $canonical = | ||
128 | exists $LOG_LEVEL_ALIASES{$level} ? $LOG_LEVEL_ALIASES{$level} : $level; | ||||
129 | 14 | 36µs | return $LOG_LEVELS{ uc($canonical) }; | ||
130 | } | ||||
131 | |||||
132 | #pod =func dump_one_line | ||||
133 | #pod | ||||
134 | #pod Given a reference, returns a one-line L<Data::Dumper> dump with keys sorted. | ||||
135 | #pod | ||||
136 | #pod =cut | ||||
137 | |||||
138 | # lazy trampoline to load Data::Dumper only on demand but then not try to | ||||
139 | # require it pointlessly each time | ||||
140 | *dump_one_line = sub { | ||||
141 | require Data::Dumper; | ||||
142 | |||||
143 | my $dumper = sub { | ||||
144 | my ($value) = @_; | ||||
145 | |||||
146 | return Data::Dumper->new( [$value] )->Indent(0)->Sortkeys(1)->Quotekeys(0) | ||||
147 | ->Terse(1)->Useqq(1)->Dump(); | ||||
148 | }; | ||||
149 | |||||
150 | my $string = $dumper->(@_); | ||||
151 | 2 | 88µs | 2 | 35µs | # spent 23µs (11+12) within Log::Any::Adapter::Util::BEGIN@151 which was called:
# once (11µs+12µs) by Log::Any::BEGIN@11 at line 151 # spent 23µs making 1 call to Log::Any::Adapter::Util::BEGIN@151
# spent 12µs making 1 call to warnings::unimport |
152 | *dump_one_line = $dumper; | ||||
153 | return $string; | ||||
154 | 1 | 3µs | }; | ||
155 | |||||
156 | #pod =func make_method | ||||
157 | #pod | ||||
158 | #pod Given a method name, a code reference and a package name, installs the code | ||||
159 | #pod reference as a method in the package. | ||||
160 | #pod | ||||
161 | #pod =cut | ||||
162 | |||||
163 | sub make_method { | ||||
164 | my ( $method, $code, $pkg ) = @_; | ||||
165 | |||||
166 | $pkg ||= caller(); | ||||
167 | 2 | 268µs | 2 | 33µs | # spent 21µs (9+12) within Log::Any::Adapter::Util::BEGIN@167 which was called:
# once (9µs+12µs) by Log::Any::BEGIN@11 at line 167 # spent 21µs making 1 call to Log::Any::Adapter::Util::BEGIN@167
# spent 12µs making 1 call to strict::unimport |
168 | *{ $pkg . "::$method" } = $code; | ||||
169 | } | ||||
170 | |||||
171 | #pod =func require_dynamic (DEPRECATED) | ||||
172 | #pod | ||||
173 | #pod Given a class name, attempts to load it via require unless the class | ||||
174 | #pod already has a constructor available. Throws an error on failure. Used | ||||
175 | #pod internally and may become private in the future. | ||||
176 | #pod | ||||
177 | #pod =cut | ||||
178 | |||||
179 | # spent 1.23ms (1.09+138µs) within Log::Any::Adapter::Util::require_dynamic which was called 2 times, avg 614µs/call:
# 2 times (1.09ms+138µs) by Log::Any::get_logger at line 84 of /opt/flows/lib/lib/perl5/Log/Any.pm, avg 614µs/call | ||||
180 | 2 | 1µs | my ($class) = @_; | ||
181 | |||||
182 | 2 | 18µs | 2 | 3µs | return 1 if $class->can('new'); # duck-type that class is loaded # spent 3µs making 2 calls to UNIVERSAL::can, avg 2µs/call |
183 | |||||
184 | 1 | 32µs | unless ( defined( eval "require $class; 1" ) ) # spent 71µs executing statements in string eval | ||
185 | { ## no critic (ProhibitStringyEval) | ||||
186 | die $@; | ||||
187 | } | ||||
188 | } | ||||
189 | |||||
190 | #pod =func read_file (DEPRECATED) | ||||
191 | #pod | ||||
192 | #pod Slurp a file. Does *not* apply any layers. Used for testing and may | ||||
193 | #pod become private in the future. | ||||
194 | #pod | ||||
195 | #pod =cut | ||||
196 | |||||
197 | sub read_file { | ||||
198 | my ($file) = @_; | ||||
199 | |||||
200 | local $/ = undef; | ||||
201 | open( my $fh, '<:utf8', $file ) ## no critic | ||||
202 | or die "cannot open '$file': $!"; | ||||
203 | my $contents = <$fh>; | ||||
204 | return $contents; | ||||
205 | } | ||||
206 | |||||
207 | #pod =func cmp_deeply (DEPRECATED) | ||||
208 | #pod | ||||
209 | #pod Compares L<dump_one_line> results for two references. Also takes a test | ||||
210 | #pod label as a third argument. Used for testing and may become private in the | ||||
211 | #pod future. | ||||
212 | #pod | ||||
213 | #pod =cut | ||||
214 | |||||
215 | sub cmp_deeply { | ||||
216 | my ( $ref1, $ref2, $name ) = @_; | ||||
217 | |||||
218 | my $tb = Test::Builder->new(); | ||||
219 | $tb->is_eq( dump_one_line($ref1), dump_one_line($ref2), $name ); | ||||
220 | } | ||||
221 | |||||
222 | # 0.XX version loaded Log::Any and some adapters relied on this happening | ||||
223 | # behind the scenes. Since Log::Any now uses this module, we load Log::Any | ||||
224 | # via require after compilation to mitigate circularity. | ||||
225 | 1 | 300ns | require Log::Any; | ||
226 | |||||
227 | 1 | 8µs | 1; | ||
228 | |||||
229 | |||||
230 | # vim: ts=4 sts=4 sw=4 et tw=75: | ||||
231 | |||||
232 | __END__ |