Filename | /home/ss5/perl5/perlbrew/perls/perl-5.22.0/lib/site_perl/5.22.0/Log/Any/Adapter/Util.pm |
Statements | Executed 4082 statements in 20.1ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
2003 | 1 | 1 | 14.3ms | 18.3ms | require_dynamic | Log::Any::Adapter::Util::
14 | 1 | 1 | 14µs | 14µs | numeric_level | Log::Any::Adapter::Util::
1 | 1 | 1 | 13µs | 13µs | BEGIN@52 | Log::Any::Adapter::Util::
1 | 1 | 1 | 10µs | 88µs | BEGIN@28 | Log::Any::Adapter::Util::
1 | 1 | 1 | 10µs | 10µs | BEGIN@1.31 | Log::Any::
1 | 1 | 1 | 8µs | 14µs | BEGIN@156 | Log::Any::Adapter::Util::
1 | 1 | 1 | 6µs | 22µs | BEGIN@10 | Log::Any::Adapter::Util::
1 | 1 | 1 | 6µs | 6µs | BEGIN@14 | Log::Any::Adapter::Util::
1 | 1 | 1 | 5µs | 6µs | BEGIN@2.32 | Log::Any::
1 | 1 | 1 | 5µs | 36µs | BEGIN@11 | Log::Any::Adapter::Util::
1 | 1 | 1 | 5µs | 8µs | BEGIN@3.33 | Log::Any::
2 | 2 | 2 | 3µs | 3µs | logging_and_detection_methods | Log::Any::Adapter::Util::
1 | 1 | 1 | 2µs | 2µs | log_level_aliases | Log::Any::Adapter::Util::
1 | 1 | 1 | 800ns | 800ns | logging_methods | 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 | dump_one_line | 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 | 25µs | 1 | 10µs | # spent 10µs within Log::Any::BEGIN@1.31 which was called:
# once (10µs+0s) by Log::Any::BEGIN@11 at line 1 # spent 10µs making 1 call to Log::Any::BEGIN@1.31 |
2 | 2 | 12µs | 2 | 8µs | # spent 6µs (5+1) within Log::Any::BEGIN@2.32 which was called:
# once (5µs+1µs) by Log::Any::BEGIN@11 at line 2 # spent 6µs making 1 call to Log::Any::BEGIN@2.32
# spent 2µs making 1 call to strict::import |
3 | 2 | 30µs | 2 | 11µs | # spent 8µs (5+3) within Log::Any::BEGIN@3.33 which was called:
# once (5µs+3µs) by Log::Any::BEGIN@11 at line 3 # spent 8µs making 1 call to Log::Any::BEGIN@3.33
# spent 3µ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 | 200ns | our $VERSION = '1.032'; | ||
9 | |||||
10 | 2 | 16µs | 2 | 37µs | # spent 22µs (6+16) within Log::Any::Adapter::Util::BEGIN@10 which was called:
# once (6µs+16µs) by Log::Any::BEGIN@11 at line 10 # spent 22µs making 1 call to Log::Any::Adapter::Util::BEGIN@10
# spent 16µs making 1 call to Exporter::import |
11 | 2 | 31µs | 2 | 67µs | # spent 36µs (5+31) within Log::Any::Adapter::Util::BEGIN@11 which was called:
# once (5µs+31µs) by Log::Any::BEGIN@11 at line 11 # spent 36µs making 1 call to Log::Any::Adapter::Util::BEGIN@11
# spent 31µs making 1 call to base::import |
12 | |||||
13 | 1 | 100ns | my %LOG_LEVELS; | ||
14 | # spent 6µs within Log::Any::Adapter::Util::BEGIN@14 which was called:
# once (6µs+0s) by Log::Any::BEGIN@11 at line 26 | ||||
15 | 1 | 7µ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 | 15µs | 1 | 6µs | } # spent 6µs making 1 call to Log::Any::Adapter::Util::BEGIN@14 |
27 | |||||
28 | 2 | 230µs | 2 | 166µs | # spent 88µs (10+78) within Log::Any::Adapter::Util::BEGIN@28 which was called:
# once (10µs+78µs) by Log::Any::BEGIN@11 at line 28 # spent 88µs making 1 call to Log::Any::Adapter::Util::BEGIN@28
# spent 78µs making 1 call to constant::import |
29 | |||||
30 | 1 | 1µ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 | 2µs | push @EXPORT_OK, keys %LOG_LEVELS; | ||
46 | |||||
47 | 1 | 2µ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 13µs within Log::Any::Adapter::Util::BEGIN@52 which was called:
# once (13µs+0s) by Log::Any::BEGIN@11 at line 66 | ||||
53 | 1 | 2µs | %LOG_LEVEL_ALIASES = ( | ||
54 | inform => 'info', | ||||
55 | warn => 'warning', | ||||
56 | err => 'error', | ||||
57 | crit => 'critical', | ||||
58 | fatal => 'critical' | ||||
59 | ); | ||||
60 | 1 | 700ns | @logging_methods = | ||
61 | qw(trace debug info notice warning error critical alert emergency); | ||||
62 | 1 | 1µs | @logging_aliases = keys(%LOG_LEVEL_ALIASES); | ||
63 | 1 | 3µs | @detection_methods = map { "is_$_" } @logging_methods; | ||
64 | 1 | 1µs | @detection_aliases = map { "is_$_" } @logging_aliases; | ||
65 | 1 | 6µs | @logging_and_detection_methods = ( @logging_methods, @detection_methods ); | ||
66 | 1 | 126µs | 1 | 13µs | } # spent 13µ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 | 3µs | # spent 800ns within Log::Any::Adapter::Util::logging_methods which was called:
# once (800ns+0s) by Log::Any::Adapter::Util::require_dynamic at line 53 of 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 | 6µs | # spent 3µs within Log::Any::Adapter::Util::logging_and_detection_methods which was called 2 times, avg 1µs/call:
# once (2µs+0s) by base::import at line 23 of Log/Any/Adapter/Base.pm
# once (1µs+0s) by Log::Any::Manager::_require_dynamic at line 16 of 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 | 4µs | # spent 2µs within Log::Any::Adapter::Util::log_level_aliases which was called:
# once (2µs+0s) by Log::Any::Adapter::Util::require_dynamic at line 50 of 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 14µs within Log::Any::Adapter::Util::numeric_level which was called 14 times, avg 1µs/call:
# 14 times (14µs+0s) by Log::Any::Adapter::Util::require_dynamic at line 59 of Log/Any/Proxy.pm, avg 1µs/call | ||||
126 | 14 | 1µs | my ($level) = @_; | ||
127 | my $canonical = | ||||
128 | 14 | 2µs | exists $LOG_LEVEL_ALIASES{$level} ? $LOG_LEVEL_ALIASES{$level} : $level; | ||
129 | 14 | 15µ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 | sub dump_one_line { | ||||
139 | my ($value) = @_; | ||||
140 | |||||
141 | return Data::Dumper->new( [$value] )->Indent(0)->Sortkeys(1)->Quotekeys(0) | ||||
142 | ->Terse(1)->Dump(); | ||||
143 | } | ||||
144 | |||||
145 | #pod =func make_method | ||||
146 | #pod | ||||
147 | #pod Given a method name, a code reference and a package name, installs the code | ||||
148 | #pod reference as a method in the package. | ||||
149 | #pod | ||||
150 | #pod =cut | ||||
151 | |||||
152 | sub make_method { | ||||
153 | my ( $method, $code, $pkg ) = @_; | ||||
154 | |||||
155 | $pkg ||= caller(); | ||||
156 | 2 | 126µs | 2 | 21µs | # spent 14µs (8+7) within Log::Any::Adapter::Util::BEGIN@156 which was called:
# once (8µs+7µs) by Log::Any::BEGIN@11 at line 156 # spent 14µs making 1 call to Log::Any::Adapter::Util::BEGIN@156
# spent 7µs making 1 call to strict::unimport |
157 | *{ $pkg . "::$method" } = $code; | ||||
158 | } | ||||
159 | |||||
160 | #pod =func require_dynamic (DEPRECATED) | ||||
161 | #pod | ||||
162 | #pod Given a class name, attempts to load it via require unless the class | ||||
163 | #pod already has a constructor available. Throws an error on failure. Used | ||||
164 | #pod internally and may become private in the future. | ||||
165 | #pod | ||||
166 | #pod =cut | ||||
167 | |||||
168 | # spent 18.3ms (14.3+4.00) within Log::Any::Adapter::Util::require_dynamic which was called 2003 times, avg 9µs/call:
# 2003 times (14.3ms+4.00ms) by Log::Any::get_logger at line 84 of Log/Any.pm, avg 9µs/call | ||||
169 | 2003 | 878µs | my ($class) = @_; | ||
170 | |||||
171 | 2003 | 18.5ms | 2003 | 3.94ms | return 1 if $class->can('new'); # duck-type that class is loaded # spent 3.94ms making 2003 calls to UNIVERSAL::can, avg 2µs/call |
172 | |||||
173 | 1 | 16µs | unless ( defined( eval "require $class; 1" ) ) # spent 39µs executing statements in string eval | ||
174 | { ## no critic (ProhibitStringyEval) | ||||
175 | die $@; | ||||
176 | } | ||||
177 | } | ||||
178 | |||||
179 | #pod =func read_file (DEPRECATED) | ||||
180 | #pod | ||||
181 | #pod Slurp a file. Does *not* apply any layers. Used for testing and may | ||||
182 | #pod become private in the future. | ||||
183 | #pod | ||||
184 | #pod =cut | ||||
185 | |||||
186 | sub read_file { | ||||
187 | my ($file) = @_; | ||||
188 | |||||
189 | local $/ = undef; | ||||
190 | open( my $fh, '<', $file ) | ||||
191 | or die "cannot open '$file': $!"; | ||||
192 | my $contents = <$fh>; | ||||
193 | return $contents; | ||||
194 | } | ||||
195 | |||||
196 | #pod =func cmp_deeply (DEPRECATED) | ||||
197 | #pod | ||||
198 | #pod Compares L<dump_one_line> results for two references. Also takes a test | ||||
199 | #pod label as a third argument. Used for testing and may become private in the | ||||
200 | #pod future. | ||||
201 | #pod | ||||
202 | #pod =cut | ||||
203 | |||||
204 | sub cmp_deeply { | ||||
205 | my ( $ref1, $ref2, $name ) = @_; | ||||
206 | |||||
207 | my $tb = Test::Builder->new(); | ||||
208 | $tb->is_eq( dump_one_line($ref1), dump_one_line($ref2), $name ); | ||||
209 | } | ||||
210 | |||||
211 | # 0.XX version loaded Log::Any and some adapters relied on this happening | ||||
212 | # behind the scenes. Since Log::Any now uses this module, we load Log::Any | ||||
213 | # via require after compilation to mitigate circularity. | ||||
214 | 1 | 300ns | require Log::Any; | ||
215 | |||||
216 | 1 | 4µs | 1; | ||
217 | |||||
218 | |||||
219 | # vim: ts=4 sts=4 sw=4 et tw=75: | ||||
220 | |||||
221 | __END__ |