← Index
NYTProf Performance Profile   « line view »
For flows_to_es.pl
  Run on Mon May 9 23:27:59 2016
Reported on Mon May 9 23:28:09 2016

Filename/opt/flows/lib/lib/perl5/Log/Any/Adapter/Util.pm
StatementsExecuted 82 statements in 1.24ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
2111.09ms1.23msLog::Any::Adapter::Util::::require_dynamicLog::Any::Adapter::Util::require_dynamic
141125µs25µsLog::Any::Adapter::Util::::numeric_levelLog::Any::Adapter::Util::numeric_level
11121µs21µsLog::Any::Adapter::Util::::BEGIN@52Log::Any::Adapter::Util::BEGIN@52
11119µs19µsLog::Any::::BEGIN@1.7 Log::Any::BEGIN@1.7
11111µs23µsLog::Any::Adapter::Util::::BEGIN@151Log::Any::Adapter::Util::BEGIN@151
11110µs28µsLog::Any::Adapter::Util::::BEGIN@10Log::Any::Adapter::Util::BEGIN@10
1119µs21µsLog::Any::Adapter::Util::::BEGIN@167Log::Any::Adapter::Util::BEGIN@167
1118µs125µsLog::Any::Adapter::Util::::BEGIN@28Log::Any::Adapter::Util::BEGIN@28
2228µs8µsLog::Any::Adapter::Util::::logging_and_detection_methodsLog::Any::Adapter::Util::logging_and_detection_methods
1118µs13µsLog::Any::::BEGIN@3.9 Log::Any::BEGIN@3.9
1118µs8µsLog::Any::Adapter::Util::::BEGIN@14Log::Any::Adapter::Util::BEGIN@14
1118µs21µsLog::Any::::BEGIN@2.8 Log::Any::BEGIN@2.8
1114µs4µsLog::Any::Adapter::Util::::log_level_aliasesLog::Any::Adapter::Util::log_level_aliases
1112µs2µsLog::Any::Adapter::Util::::logging_methodsLog::Any::Adapter::Util::logging_methods
0000s0sLog::Any::Adapter::Util::::__ANON__[:148]Log::Any::Adapter::Util::__ANON__[:148]
0000s0sLog::Any::Adapter::Util::::__ANON__[:154]Log::Any::Adapter::Util::__ANON__[:154]
0000s0sLog::Any::Adapter::Util::::cmp_deeplyLog::Any::Adapter::Util::cmp_deeply
0000s0sLog::Any::Adapter::Util::::detection_aliasesLog::Any::Adapter::Util::detection_aliases
0000s0sLog::Any::Adapter::Util::::detection_methodsLog::Any::Adapter::Util::detection_methods
0000s0sLog::Any::Adapter::Util::::logging_aliasesLog::Any::Adapter::Util::logging_aliases
0000s0sLog::Any::Adapter::Util::::make_methodLog::Any::Adapter::Util::make_method
0000s0sLog::Any::Adapter::Util::::read_fileLog::Any::Adapter::Util::read_file
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1251µs119µ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
use 5.008001;
# spent 19µs making 1 call to Log::Any::BEGIN@1.7
2226µs235µ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
use strict;
# spent 21µs making 1 call to Log::Any::BEGIN@2.8 # spent 14µs making 1 call to strict::import
3252µs218µ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
use warnings;
# spent 13µs making 1 call to Log::Any::BEGIN@3.9 # spent 5µs making 1 call to warnings::import
4
5package Log::Any::Adapter::Util;
6
7# ABSTRACT: Common utility functions for Log::Any
81700nsour $VERSION = '1.040';
9
10274µs246µ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
use Exporter;
# spent 28µs making 1 call to Log::Any::Adapter::Util::BEGIN@10 # spent 18µs making 1 call to Exporter::import
1116µsour @ISA = qw/Exporter/;
12
131200nsmy %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
BEGIN {
1518µ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 );
26128µs18µs}
# spent 8µs making 1 call to Log::Any::Adapter::Util::BEGIN@14
27
282179µs2241µ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
use constant \%LOG_LEVELS;
# spent 125µs making 1 call to Log::Any::Adapter::Util::BEGIN@28 # spent 116µs making 1 call to constant::import
29
3012µsour @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
4513µspush @EXPORT_OK, keys %LOG_LEVELS;
46
4713µsour %EXPORT_TAGS = ( 'levels' => [ keys %LOG_LEVELS ] );
48
491100nsmy ( %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
BEGIN {
5314µs %LOG_LEVEL_ALIASES = (
54 inform => 'info',
55 warn => 'warning',
56 err => 'error',
57 crit => 'critical',
58 fatal => 'critical'
59 );
6012µs @logging_methods =
61 qw(trace debug info notice warning error critical alert emergency);
6212µs @logging_aliases = keys(%LOG_LEVEL_ALIASES);
6315µs @detection_methods = map { "is_$_" } @logging_methods;
6412µs @detection_aliases = map { "is_$_" } @logging_aliases;
6518µs @logging_and_detection_methods = ( @logging_methods, @detection_methods );
661292µs121µ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
7414µ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
sub logging_methods { @logging_methods }
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
82sub 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
90216µ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
sub logging_and_detection_methods { @logging_and_detection_methods }
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
9918µ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
sub log_level_aliases { %LOG_LEVEL_ALIASES }
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
108sub 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
116sub 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
sub numeric_level {
126143µs my ($level) = @_;
127145µs my $canonical =
128 exists $LOG_LEVEL_ALIASES{$level} ? $LOG_LEVEL_ALIASES{$level} : $level;
1291436µ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->(@_);
151288µs235µ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
no warnings 'redefine';
# 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;
15413µ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
163sub make_method {
164 my ( $method, $code, $pkg ) = @_;
165
166 $pkg ||= caller();
1672268µs233µ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
no strict 'refs';
# 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
sub require_dynamic {
18021µs my ($class) = @_;
181
182218µs23µ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
184132µ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
197sub 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
215sub 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.
2251300nsrequire Log::Any;
226
22718µs1;
228
229
230# vim: ts=4 sts=4 sw=4 et tw=75:
231
232__END__