← Index
NYTProf Performance Profile   « block view • line view • sub view »
For mentat.storage.mongo.pl
  Run on Tue Jun 24 10:04:38 2014
Reported on Tue Jun 24 10:05:20 2014

Filename/usr/local/lib/site_perl/Log/Core/Essentials.pm
StatementsExecuted 92 statements in 1.10ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
51146µs55µsLog::Core::Essentials::::severity_as_strLog::Core::Essentials::severity_as_str
11117µs42µsLog::Core::Essentials::::BEGIN@112Log::Core::Essentials::BEGIN@112
11113µs16µsLog::Core::Essentials::::BEGIN@2Log::Core::Essentials::BEGIN@2
11111µs62µsLog::Core::Essentials::::BEGIN@114Log::Core::Essentials::BEGIN@114
11111µs35µsLog::Core::Essentials::::BEGIN@113Log::Core::Essentials::BEGIN@113
11110µs35µsLog::Core::Essentials::::BEGIN@110Log::Core::Essentials::BEGIN@110
1119µs33µsLog::Core::Essentials::::BEGIN@118Log::Core::Essentials::BEGIN@118
1119µs45µsLog::Core::Essentials::::BEGIN@67Log::Core::Essentials::BEGIN@67
1118µs33µsLog::Core::Essentials::::BEGIN@111Log::Core::Essentials::BEGIN@111
1118µs50µsLog::Core::Essentials::::BEGIN@99Log::Core::Essentials::BEGIN@99
1117µs11µsLog::Core::Essentials::::BEGIN@3Log::Core::Essentials::BEGIN@3
1117µs34µsLog::Core::Essentials::::BEGIN@100Log::Core::Essentials::BEGIN@100
1117µs38µsLog::Core::Essentials::::BEGIN@79Log::Core::Essentials::BEGIN@79
1117µs29µsLog::Core::Essentials::::BEGIN@68Log::Core::Essentials::BEGIN@68
1116µs32µsLog::Core::Essentials::::BEGIN@104Log::Core::Essentials::BEGIN@104
1116µs30µsLog::Core::Essentials::::BEGIN@107Log::Core::Essentials::BEGIN@107
1116µs31µsLog::Core::Essentials::::BEGIN@116Log::Core::Essentials::BEGIN@116
1116µs35µsLog::Core::Essentials::::BEGIN@102Log::Core::Essentials::BEGIN@102
1116µs31µsLog::Core::Essentials::::BEGIN@101Log::Core::Essentials::BEGIN@101
1116µs31µsLog::Core::Essentials::::BEGIN@106Log::Core::Essentials::BEGIN@106
1116µs45µsLog::Core::Essentials::::BEGIN@115Log::Core::Essentials::BEGIN@115
5116µs6µsLog::Core::Essentials::::CORE:matchLog::Core::Essentials::CORE:match (opcode)
1116µs30µsLog::Core::Essentials::::BEGIN@117Log::Core::Essentials::BEGIN@117
1116µs29µsLog::Core::Essentials::::BEGIN@103Log::Core::Essentials::BEGIN@103
1116µs36µsLog::Core::Essentials::::BEGIN@105Log::Core::Essentials::BEGIN@105
1114µs4µsLog::Core::Essentials::::BEGIN@78Log::Core::Essentials::BEGIN@78
1112µs2µsLog::Core::Essentials::::ENDLog::Core::Essentials::END
0000s0sLog::Core::Essentials::::severitiesLog::Core::Essentials::severities
0000s0sLog::Core::Essentials::::severity_as_intLog::Core::Essentials::severity_as_int
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package Log::Core::Essentials;
2221µs219µs
# spent 16µs (13+3) within Log::Core::Essentials::BEGIN@2 which was called: # once (13µs+3µs) by Log::Loger::BEGIN@116 at line 2
use strict;
# spent 16µs making 1 call to Log::Core::Essentials::BEGIN@2 # spent 3µs making 1 call to strict::import
3255µs216µs
# spent 11µs (7+4) within Log::Core::Essentials::BEGIN@3 which was called: # once (7µs+4µs) by Log::Loger::BEGIN@116 at line 3
use warnings;
# spent 11µs making 1 call to Log::Core::Essentials::BEGIN@3 # spent 4µs making 1 call to warnings::import
4
5#*******************************************************************************
6#
7# DOCUMENTATION SECTION
8#
9#*******************************************************************************
10
11=head1 NAME
12
13Log::Core::Essentials - Essential methods and constants for whole logging framework
14
15=head1 SYNOPSIS
16
17 use Log::Core::Essentials;
18
19 # Get list of all valid severity values
20 my @severities = Log::Core::Essentials->severities();
21
22 # Translate given severity into integer representation
23 my $result = Log::Core::Essentials->severity_as_int('EMERG');
24
25 # Translate given severity into string representation
26 my $result = Log::Core::Essentials->severity_as_str(4);
27
28=head1 DESCRIPTION
29
30This class contains essential contants for whole logging framework, and
31methods for converting message severities from string to their integer
32representations, and vice versa.
33
34=head1 AUTHOR
35
36Jan Mach
37Cesnet, z.s.p.o
38jan.mach@cesnet.cz
39http://www.cesnet.cz
40
41=head1 COPYRIGHT
42
43This program is free software; you can redistribute
44it and/or modify it under the same terms as Perl itself.
45
46The full text of the license can be found in the
47LICENSE file included with this module.
48
49
50=head1 SEE ALSO
51
52perl(1).
53
54=head1 FUNCTION REFERENCE
55
56=over 4
57
58=cut
59
60#*******************************************************************************
61#
62# INITIALIZATION AND CLEANUP SECTION
63#
64#*******************************************************************************
65
66#-- Perl core modules ---------------------------------------------------------#
67227µs281µs
# spent 45µs (9+36) within Log::Core::Essentials::BEGIN@67 which was called: # once (9µs+36µs) by Log::Loger::BEGIN@116 at line 67
use Carp;
# spent 45µs making 1 call to Log::Core::Essentials::BEGIN@67 # spent 36µs making 1 call to Exporter::import
68232µs251µs
# spent 29µs (7+22) within Log::Core::Essentials::BEGIN@68 which was called: # once (7µs+22µs) by Log::Loger::BEGIN@116 at line 68
use Scalar::Util 'blessed';
# spent 29µs making 1 call to Log::Core::Essentials::BEGIN@68 # spent 22µs making 1 call to Exporter::import
69
70#use Data::Dumper; #-+-> DEVEL ONLY <-+-#
71#use Smart::Comments; #-+-> DEVEL ONLY <-+-#
72
73#-- Perl CPAN modules ---------------------------------------------------------#
74
75#-- Custom application modules ------------------------------------------------#
76
77#-- Module initializations ----------------------------------------------------#
78
# spent 4µs within Log::Core::Essentials::BEGIN@78 which was called: # once (4µs+0s) by Log::Loger::BEGIN@116 at line 82
BEGIN {
79228µs268µs
# spent 38µs (7+31) within Log::Core::Essentials::BEGIN@79 which was called: # once (7µs+31µs) by Log::Loger::BEGIN@116 at line 79
use vars qw($VERSION $DEVEL);
# spent 38µs making 1 call to Log::Core::Essentials::BEGIN@79 # spent 31µs making 1 call to vars::import
8023µs $VERSION = '0.01';
81 $DEVEL = 0;
82137µs14µs}
# spent 4µs making 1 call to Log::Core::Essentials::BEGIN@78
83
84
85#-- Module clean-up code (global destructor) ----------------------------------#
8612µs
# spent 2µs within Log::Core::Essentials::END which was called: # once (2µs+0s) by main::RUNTIME at line 0 of mentat.storage.mongo.pl
END {
87
88}
89
90#*******************************************************************************
91#
92# CONSTANTS AND GLOBAL VARIABLES DEFINITION SECTION
93#
94#*******************************************************************************
95
96#-- Constants -----------------------------------------------------------------#
97
98# Log severity integer values
99226µs293µs
# spent 50µs (8+42) within Log::Core::Essentials::BEGIN@99 which was called: # once (8µs+42µs) by Log::Loger::BEGIN@116 at line 99
use constant EMAIL => 8; # special severity - send email
# spent 50µs making 1 call to Log::Core::Essentials::BEGIN@99 # spent 42µs making 1 call to constant::import
100228µs260µs
# spent 34µs (7+27) within Log::Core::Essentials::BEGIN@100 which was called: # once (7µs+27µs) by Log::Loger::BEGIN@116 at line 100
use constant EMERG => 7; # system is unusable
# spent 34µs making 1 call to Log::Core::Essentials::BEGIN@100 # spent 27µs making 1 call to constant::import
101223µs256µs
# spent 31µs (6+25) within Log::Core::Essentials::BEGIN@101 which was called: # once (6µs+25µs) by Log::Loger::BEGIN@116 at line 101
use constant ALERT => 6; # action must be taken immediately
# spent 31µs making 1 call to Log::Core::Essentials::BEGIN@101 # spent 25µs making 1 call to constant::import
102223µs264µs
# spent 35µs (6+29) within Log::Core::Essentials::BEGIN@102 which was called: # once (6µs+29µs) by Log::Loger::BEGIN@116 at line 102
use constant CRIT => 5; # critical conditions
# spent 35µs making 1 call to Log::Core::Essentials::BEGIN@102 # spent 29µs making 1 call to constant::import
103226µs253µs
# spent 29µs (6+24) within Log::Core::Essentials::BEGIN@103 which was called: # once (6µs+24µs) by Log::Loger::BEGIN@116 at line 103
use constant ERROR => 4; # error conditions
# spent 29µs making 1 call to Log::Core::Essentials::BEGIN@103 # spent 24µs making 1 call to constant::import
104222µs258µs
# spent 32µs (6+26) within Log::Core::Essentials::BEGIN@104 which was called: # once (6µs+26µs) by Log::Loger::BEGIN@116 at line 104
use constant WARNING => 3; # warning conditions
# spent 32µs making 1 call to Log::Core::Essentials::BEGIN@104 # spent 26µs making 1 call to constant::import
105223µs267µs
# spent 36µs (6+31) within Log::Core::Essentials::BEGIN@105 which was called: # once (6µs+31µs) by Log::Loger::BEGIN@116 at line 105
use constant NOTICE => 2; # normal, but significant, condition
# spent 36µs making 1 call to Log::Core::Essentials::BEGIN@105 # spent 31µs making 1 call to constant::import
106222µs256µs
# spent 31µs (6+25) within Log::Core::Essentials::BEGIN@106 which was called: # once (6µs+25µs) by Log::Loger::BEGIN@116 at line 106
use constant INFO => 1; # informational message
# spent 31µs making 1 call to Log::Core::Essentials::BEGIN@106 # spent 25µs making 1 call to constant::import
107227µs253µs
# spent 30µs (6+23) within Log::Core::Essentials::BEGIN@107 which was called: # once (6µs+23µs) by Log::Loger::BEGIN@116 at line 107
use constant DEBUG => 0; # debug-level message
# spent 30µs making 1 call to Log::Core::Essentials::BEGIN@107 # spent 24µs making 1 call to constant::import
108
109# Log severity string values
110226µs260µs
# spent 35µs (10+25) within Log::Core::Essentials::BEGIN@110 which was called: # once (10µs+25µs) by Log::Loger::BEGIN@116 at line 110
use constant EMAIL_STR => 'EMAIL'; # special severity - send email
# spent 35µs making 1 call to Log::Core::Essentials::BEGIN@110 # spent 25µs making 1 call to constant::import
111234µs258µs
# spent 33µs (8+25) within Log::Core::Essentials::BEGIN@111 which was called: # once (8µs+25µs) by Log::Loger::BEGIN@116 at line 111
use constant EMERG_STR => 'EMERG'; # system is unusable
# spent 33µs making 1 call to Log::Core::Essentials::BEGIN@111 # spent 25µs making 1 call to constant::import
112224µs267µs
# spent 42µs (17+25) within Log::Core::Essentials::BEGIN@112 which was called: # once (17µs+25µs) by Log::Loger::BEGIN@116 at line 112
use constant ALERT_STR => 'ALERT'; # action must be taken immediately
# spent 42µs making 1 call to Log::Core::Essentials::BEGIN@112 # spent 25µs making 1 call to constant::import
113224µs259µs
# spent 35µs (11+24) within Log::Core::Essentials::BEGIN@113 which was called: # once (11µs+24µs) by Log::Loger::BEGIN@116 at line 113
use constant CRIT_STR => 'CRIT'; # critical conditions
# spent 35µs making 1 call to Log::Core::Essentials::BEGIN@113 # spent 24µs making 1 call to constant::import
114226µs2112µs
# spent 62µs (11+50) within Log::Core::Essentials::BEGIN@114 which was called: # once (11µs+50µs) by Log::Loger::BEGIN@116 at line 114
use constant ERROR_STR => 'ERROR'; # error conditions
# spent 62µs making 1 call to Log::Core::Essentials::BEGIN@114 # spent 50µs making 1 call to constant::import
115224µs283µs
# spent 45µs (6+38) within Log::Core::Essentials::BEGIN@115 which was called: # once (6µs+38µs) by Log::Loger::BEGIN@116 at line 115
use constant WARNING_STR => 'WARNING'; # warning conditions
# spent 45µs making 1 call to Log::Core::Essentials::BEGIN@115 # spent 38µs making 1 call to constant::import
116222µs255µs
# spent 31µs (6+24) within Log::Core::Essentials::BEGIN@116 which was called: # once (6µs+24µs) by Log::Loger::BEGIN@116 at line 116
use constant NOTICE_STR => 'NOTICE'; # normal, but significant, condition
# spent 31µs making 1 call to Log::Core::Essentials::BEGIN@116 # spent 24µs making 1 call to constant::import
117223µs254µs
# spent 30µs (6+24) within Log::Core::Essentials::BEGIN@117 which was called: # once (6µs+24µs) by Log::Loger::BEGIN@116 at line 117
use constant INFO_STR => 'INFO'; # informational message
# spent 30µs making 1 call to Log::Core::Essentials::BEGIN@117 # spent 24µs making 1 call to constant::import
1182398µs256µs
# spent 33µs (9+24) within Log::Core::Essentials::BEGIN@118 which was called: # once (9µs+24µs) by Log::Loger::BEGIN@116 at line 118
use constant DEBUG_STR => 'DEBUG'; # debug-level message
# spent 33µs making 1 call to Log::Core::Essentials::BEGIN@118 # spent 24µs making 1 call to constant::import
119
120#-- Static public class variables (our) ---------------------------------------#
121
122#-- Static protected class variables (my) -------------------------------------#
123
124# Translation table from string severity labels to integer representations
125# We MUST NOT USE '=>' symbol in the hash definition, otherwise the constant
126# names left of it would be automatically quoted and interpreted as strings.
12714µsmy %SEVERITY2INT = ( EMAIL_STR , EMAIL,
128 EMERG_STR , EMERG,
129 ALERT_STR , ALERT,
130 CRIT_STR , CRIT,
131 ERROR_STR , ERROR,
132 WARNING_STR , WARNING,
133 NOTICE_STR , NOTICE,
134 INFO_STR , INFO,
135 DEBUG_STR , DEBUG,
136 );
137
138# Translation table from integer representations to string severity labels
13912µsmy @INT2SEVERITY = ( DEBUG_STR,
140 INFO_STR,
141 NOTICE_STR,
142 WARNING_STR,
143 ERROR_STR,
144 CRIT_STR,
145 ALERT_STR,
146 EMERG_STR,
147 EMAIL_STR,
148 );
149
150#*******************************************************************************
151#
152# IMPLEMENTATION SECTION
153#
154#*******************************************************************************
155
156=item severities() [PUBLIC,STATIC]
157
158 Usage : Log::Core::Essentials->severities();
159 Purpose : Get list of all valid severities
160 Arguments : None
161 Returns : ARRAY of STRINGS @severities
162 Throws : Croaks, if not invoked on class
163
164=cut
165
166sub severities()
167{
168 my $class = shift;
169 croak ((caller(0))[3] . ": class method invoked on object") if blessed($class);
170 return @INT2SEVERITY;
171}
172
173=item severity_as_int($) [PUBLIC,STATIC]
174
175 Usage : Log::Core::Essentials->severity_as_int('DEBUG')
176 Purpose : Convert severity value in integer or string into corresponding integer value
177 Arguments : MIXED $severity - integer or string severity to convert, strings are case insensitive
178 Returns : UNDEF on FAILURE, INTEGER representation of given severity on SUCCESS
179 Throws : Croaks, if not invoked on class
180
181=cut
182
183sub severity_as_int($)
184{
185 my $class = shift;
186 croak ((caller(0))[3] . ": class method invoked on object") if blessed($class);
187 my ($severity,) = @_;
188
189 # Return undefined value if severity was not specified
190 return undef unless (defined($severity));
191
192 # Perform conversion to integer only if the argument is empty string or not a number
193 if ($severity =~ /^$|[^\d]+/) {
194 $severity = $SEVERITY2INT{uc($severity)};
195 }
196
197 # Return undefined value if the integer is not a valid severity value
198 return undef unless (defined($severity) and defined($INT2SEVERITY[$severity]));
199
200 # Othervise return valid value
201 return $severity;
202}
203
204=item severity_as_str [PUBLIC,STATIC]
205
206 Usage : Log::Core::Essentials->severity_as_str(7)
207 Purpose : Convert severity value in integer or string into corresponding string value
208 Arguments : MIXED $severity - integer or string severity to convert, strings are case insensitive
209 Returns : UNDEF on FAILURE, STRING representation of given severity on SUCCESS
210 Throws : Croaks, if not invoked on class
211
212=cut
213
214sub severity_as_str($)
215
# spent 55µs (46+8) within Log::Core::Essentials::severity_as_str which was called 5 times, avg 11µs/call: # 5 times (46µs+8µs) by Log::Loger::log at line 484 of Log/Loger.pm, avg 11µs/call
{
2164058µs my $class = shift;
21753µs croak ((caller(0))[3] . ": class method invoked on object") if blessed($class);
# spent 3µs making 5 calls to Scalar::Util::blessed, avg 520ns/call
218 my ($severity,) = @_;
219
220 # Return undefined value if severity was not specified
221 return undef unless (defined($severity));
222
223 # Normalize the severity to the uppercase
224 $severity = uc($severity);
225
226 # Perform conversion only if the argument is a number
22756µs if ($severity =~ /[\d]+/) {
# spent 6µs making 5 calls to Log::Core::Essentials::CORE:match, avg 1µs/call
228 $severity = $INT2SEVERITY[int($severity)];
229 }
230
231 # Return undefined value if the integer is not a valid severity value
232 return undef unless (defined($severity) and defined($SEVERITY2INT{$severity}));
233
234 # Othervise return valid value
235 return $severity;
236}
237
238=pod
239
240=back
241
242=cut
243
24415µs1;
 
# spent 6µs within Log::Core::Essentials::CORE:match which was called 5 times, avg 1µs/call: # 5 times (6µs+0s) by Log::Core::Essentials::severity_as_str at line 227, avg 1µs/call
sub Log::Core::Essentials::CORE:match; # opcode