Profile of Log/Log4perl/Level.pm

← Index
NYTProf Performance Profile «block view•line view•sub view»
For xt/tapper-mcp-scheduler-with-db-longrun.t
Run on Tue May 22 17:18:39 2012
Reported on Tue May 22 17:22:53 2012

Filename | /2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/Log/Log4perl/Level.pm
Statements | Executed 551 statements in 1.42ms

Subroutines
Calls | P | F | Exclusive Time | Inclusive Time | Subroutine
--- | --- | --- | --- | --- | ---
8 | 8 | 8 | 378µs | 378µs | Log::Log4perl::Level::::importLog::Log4perl::Level::import
8 | 8 | 1 | 31µs | 31µs | Log::Log4perl::Level::::add_priorityLog::Log4perl::Level::add_priority
1 | 1 | 1 | 19µs | 19µs | Log::Log4perl::Level::::BEGIN@5Log::Log4perl::Level::BEGIN@5
8 | 1 | 1 | 14µs | 14µs | Log::Log4perl::Level::::isGreaterOrEqualLog::Log4perl::Level::isGreaterOrEqual
1 | 1 | 1 | 10µs | 12µs | Log::Log4perl::Level::::BEGIN@6Log::Log4perl::Level::BEGIN@6
1 | 1 | 1 | 9µs | 61µs | Log::Log4perl::Level::::BEGIN@8Log::Log4perl::Level::BEGIN@8
1 | 1 | 1 | 9µs | 60µs | Log::Log4perl::Level::::BEGIN@13Log::Log4perl::Level::BEGIN@13
1 | 1 | 1 | 7µs | 57µs | Log::Log4perl::Level::::BEGIN@23Log::Log4perl::Level::BEGIN@23
1 | 1 | 1 | 7µs | 14µs | Log::Log4perl::Level::::BEGIN@7Log::Log4perl::Level::BEGIN@7
1 | 1 | 1 | 6µs | 17µs | Log::Log4perl::Level::::BEGIN@22Log::Log4perl::Level::BEGIN@22
1 | 1 | 1 | 6µs | 33µs | Log::Log4perl::Level::::BEGIN@16Log::Log4perl::Level::BEGIN@16
1 | 1 | 1 | 6µs | 28µs | Log::Log4perl::Level::::BEGIN@20Log::Log4perl::Level::BEGIN@20
1 | 1 | 1 | 6µs | 29µs | Log::Log4perl::Level::::BEGIN@14Log::Log4perl::Level::BEGIN@14
1 | 1 | 1 | 6µs | 28µs | Log::Log4perl::Level::::BEGIN@18Log::Log4perl::Level::BEGIN@18
1 | 1 | 1 | 6µs | 28µs | Log::Log4perl::Level::::BEGIN@17Log::Log4perl::Level::BEGIN@17
1 | 1 | 1 | 6µs | 28µs | Log::Log4perl::Level::::BEGIN@15Log::Log4perl::Level::BEGIN@15
1 | 1 | 1 | 5µs | 28µs | Log::Log4perl::Level::::BEGIN@19Log::Log4perl::Level::BEGIN@19
0 | 0 | 0 | 0s | 0s | Log::Log4perl::Level::::get_higher_levelLog::Log4perl::Level::get_higher_level
0 | 0 | 0 | 0s | 0s | Log::Log4perl::Level::::get_lower_levelLog::Log4perl::Level::get_lower_level
0 | 0 | 0 | 0s | 0s | Log::Log4perl::Level::::is_validLog::Log4perl::Level::is_valid
0 | 0 | 0 | 0s | 0s | Log::Log4perl::Level::::newLog::Log4perl::Level::new
0 | 0 | 0 | 0s | 0s | Log::Log4perl::Level::::numericallyLog::Log4perl::Level::numerically
0 | 0 | 0 | 0s | 0s | Log::Log4perl::Level::::to_LogDispatch_stringLog::Log4perl::Level::to_LogDispatch_string
0 | 0 | 0 | 0s | 0s | Log::Log4perl::Level::::to_levelLog::Log4perl::Level::to_level
0 | 0 | 0 | 0s | 0s | Log::Log4perl::Level::::to_priorityLog::Log4perl::Level::to_priority

Call graph for these subroutines as a Graphviz dot language file.

Line | State ments | Time on line | Calls | Time in subs | Code
--- | --- | --- | --- | --- | ---
1 |  |  |  |  | ###############r###################################
2 |  |  |  |  | package Log::Log4perl::Level;
3 |  |  |  |  | ##################################################
4 |  |  |  |  |
5 | 3 | 28µs | 1 | 19µs | # spent 19µs within Log::Log4perl::Level::BEGIN@5 which was called: # once (19µs+0s) by Log::Log4perl::Logger::BEGIN@10 at line 5 use 5.006; # spent 19µs making 1 call to Log::Log4perl::Level::BEGIN@5
6 | 3 | 17µs | 2 | 14µs | # spent 12µs (10+2) within Log::Log4perl::Level::BEGIN@6 which was called: # once (10µs+2µs) by Log::Log4perl::Logger::BEGIN@10 at line 6 use strict; # spent 12µs making 1 call to Log::Log4perl::Level::BEGIN@6 # spent 2µs making 1 call to strict::import
7 | 3 | 16µs | 2 | 22µs | # spent 14µs (7+7) within Log::Log4perl::Level::BEGIN@7 which was called: # once (7µs+7µs) by Log::Log4perl::Logger::BEGIN@10 at line 7 use warnings; # spent 14µs making 1 call to Log::Log4perl::Level::BEGIN@7 # spent 8µs making 1 call to warnings::import
8 | 3 | 23µs | 2 | 112µs | # spent 61µs (9+51) within Log::Log4perl::Level::BEGIN@8 which was called: # once (9µs+51µs) by Log::Log4perl::Logger::BEGIN@10 at line 8 use Carp; # spent 61µs making 1 call to Log::Log4perl::Level::BEGIN@8 # spent 52µs making 1 call to Exporter::import
9 |  |  |  |  |
10 |  |  |  |  | # log4j, for whatever reason, puts 0 as all and MAXINT as OFF.
11 |  |  |  |  | # this seems less optimal, as more logging would imply a higher
12 |  |  |  |  | # level. But oh well. Probably some brokenness that has persisted. :)
13 | 3 | 22µs | 2 | 112µs | # spent 60µs (9+51) within Log::Log4perl::Level::BEGIN@13 which was called: # once (9µs+51µs) by Log::Log4perl::Logger::BEGIN@10 at line 13 use constant ALL_INT => 0; # spent 60µs making 1 call to Log::Log4perl::Level::BEGIN@13 # spent 52µs making 1 call to constant::import
14 | 3 | 21µs | 2 | 53µs | # spent 29µs (6+24) within Log::Log4perl::Level::BEGIN@14 which was called: # once (6µs+24µs) by Log::Log4perl::Logger::BEGIN@10 at line 14 use constant TRACE_INT => 5000; # spent 29µs making 1 call to Log::Log4perl::Level::BEGIN@14 # spent 24µs making 1 call to constant::import
15 | 3 | 26µs | 2 | 52µs | # spent 28µs (6+23) within Log::Log4perl::Level::BEGIN@15 which was called: # once (6µs+23µs) by Log::Log4perl::Logger::BEGIN@10 at line 15 use constant DEBUG_INT => 10000; # spent 28µs making 1 call to Log::Log4perl::Level::BEGIN@15 # spent 23µs making 1 call to constant::import
16 | 3 | 17µs | 2 | 61µs | # spent 33µs (6+28) within Log::Log4perl::Level::BEGIN@16 which was called: # once (6µs+28µs) by Log::Log4perl::Logger::BEGIN@10 at line 16 use constant INFO_INT => 20000; # spent 33µs making 1 call to Log::Log4perl::Level::BEGIN@16 # spent 28µs making 1 call to constant::import
17 | 3 | 17µs | 2 | 51µs | # spent 28µs (6+23) within Log::Log4perl::Level::BEGIN@17 which was called: # once (6µs+23µs) by Log::Log4perl::Logger::BEGIN@10 at line 17 use constant WARN_INT => 30000; # spent 28µs making 1 call to Log::Log4perl::Level::BEGIN@17 # spent 23µs making 1 call to constant::import
18 | 3 | 17µs | 2 | 50µs | # spent 28µs (6+22) within Log::Log4perl::Level::BEGIN@18 which was called: # once (6µs+22µs) by Log::Log4perl::Logger::BEGIN@10 at line 18 use constant ERROR_INT => 40000; # spent 28µs making 1 call to Log::Log4perl::Level::BEGIN@18 # spent 22µs making 1 call to constant::import
19 | 3 | 25µs | 2 | 50µs | # spent 28µs (5+22) within Log::Log4perl::Level::BEGIN@19 which was called: # once (5µs+22µs) by Log::Log4perl::Logger::BEGIN@10 at line 19 use constant FATAL_INT => 50000; # spent 28µs making 1 call to Log::Log4perl::Level::BEGIN@19 # spent 22µs making 1 call to constant::import
20 | 3 | 21µs | 2 | 51µs | # spent 28µs (6+22) within Log::Log4perl::Level::BEGIN@20 which was called: # once (6µs+22µs) by Log::Log4perl::Logger::BEGIN@10 at line 20 use constant OFF_INT => (2 ** 31) - 1; # spent 28µs making 1 call to Log::Log4perl::Level::BEGIN@20 # spent 22µs making 1 call to constant::import
21 |  |  |  |  |
22 | 3 | 19µs | 2 | 27µs | # spent 17µs (6+10) within Log::Log4perl::Level::BEGIN@22 which was called: # once (6µs+10µs) by Log::Log4perl::Logger::BEGIN@10 at line 22 no strict qw(refs); # spent 17µs making 1 call to Log::Log4perl::Level::BEGIN@22 # spent 10µs making 1 call to strict::unimport
23 | 3 | 668µs | 2 | 107µs | # spent 57µs (7+50) within Log::Log4perl::Level::BEGIN@23 which was called: # once (7µs+50µs) by Log::Log4perl::Logger::BEGIN@10 at line 23 use vars qw(%PRIORITY %LEVELS %SYSLOG %L4P_TO_LD); # spent 57µs making 1 call to Log::Log4perl::Level::BEGIN@23 # spent 50µs making 1 call to vars::import
24 |  |  |  |  |
25 | 1 | 700ns |  |  | %PRIORITY = (); # unless (%PRIORITY);
26 | 1 | 500ns |  |  | %LEVELS = () unless (%LEVELS);
27 | 1 | 200ns |  |  | %SYSLOG = () unless (%SYSLOG);
28 | 1 | 500ns |  |  | %L4P_TO_LD = () unless (%L4P_TO_LD);
29 |  |  |  |  |
30 |  |  |  |  | # spent 31µs within Log::Log4perl::Level::add_priority which was called 8 times, avg 4µs/call: # once (7µs+0s) by Log::Log4perl::Logger::BEGIN@10 at line 59 # once (4µs+0s) by Log::Log4perl::Logger::BEGIN@10 at line 66 # once (4µs+0s) by Log::Log4perl::Logger::BEGIN@10 at line 60 # once (4µs+0s) by Log::Log4perl::Logger::BEGIN@10 at line 64 # once (4µs+0s) by Log::Log4perl::Logger::BEGIN@10 at line 61 # once (3µs+0s) by Log::Log4perl::Logger::BEGIN@10 at line 62 # once (3µs+0s) by Log::Log4perl::Logger::BEGIN@10 at line 63 # once (3µs+0s) by Log::Log4perl::Logger::BEGIN@10 at line 65 sub add_priority {
31 | 56 | 46µs |  |  | my ($prio, $intval, $syslog, $log_dispatch_level) = @_;
32 |  |  |  |  | $prio = uc($prio); # just in case;
33 |  |  |  |  |
34 |  |  |  |  | $PRIORITY{$prio} = $intval;
35 |  |  |  |  | $LEVELS{$intval} = $prio;
36 |  |  |  |  |
37 |  |  |  |  | # Set up the mapping between Log4perl integer levels and
38 |  |  |  |  | # Log::Dispatch levels
39 |  |  |  |  | # Note: Log::Dispatch uses the following levels:
40 |  |  |  |  | # 0 debug
41 |  |  |  |  | # 1 info
42 |  |  |  |  | # 2 notice
43 |  |  |  |  | # 3 warning
44 |  |  |  |  | # 4 error
45 |  |  |  |  | # 5 critical
46 |  |  |  |  | # 6 alert
47 |  |  |  |  | # 7 emergency
48 |  |  |  |  |
49 |  |  |  |  | # The equivalent Log::Dispatch level is optional, set it to
50 |  |  |  |  | # the highest value (7=emerg) if it's not provided.
51 |  |  |  |  | $log_dispatch_level = 7 unless defined $log_dispatch_level;
52 |  |  |  |  |
53 |  |  |  |  | $L4P_TO_LD{$prio} = $log_dispatch_level;
54 |  |  |  |  |
55 |  |  |  |  | $SYSLOG{$prio} = $syslog if defined($syslog);
56 |  |  |  |  | }
57 |  |  |  |  |
58 |  |  |  |  | # create the basic priorities
59 | 1 | 2µs | 1 | 7µs | add_priority("OFF", OFF_INT, -1, 7); # spent 7µs making 1 call to Log::Log4perl::Level::add_priority
60 | 1 | 1µs | 1 | 4µs | add_priority("FATAL", FATAL_INT, 0, 7); # spent 4µs making 1 call to Log::Log4perl::Level::add_priority
61 | 1 | 900ns | 1 | 4µs | add_priority("ERROR", ERROR_INT, 3, 4); # spent 4µs making 1 call to Log::Log4perl::Level::add_priority
62 | 1 | 800ns | 1 | 3µs | add_priority("WARN", WARN_INT, 4, 3); # spent 3µs making 1 call to Log::Log4perl::Level::add_priority
63 | 1 | 900ns | 1 | 3µs | add_priority("INFO", INFO_INT, 6, 1); # spent 3µs making 1 call to Log::Log4perl::Level::add_priority
64 | 1 | 800ns | 1 | 4µs | add_priority("DEBUG", DEBUG_INT, 7, 0); # spent 4µs making 1 call to Log::Log4perl::Level::add_priority
65 | 1 | 800ns | 1 | 3µs | add_priority("TRACE", TRACE_INT, 8, 0); # spent 3µs making 1 call to Log::Log4perl::Level::add_priority
66 | 1 | 700ns | 1 | 4µs | add_priority("ALL", ALL_INT, 8, 0); # spent 4µs making 1 call to Log::Log4perl::Level::add_priority
67 |  |  |  |  |
68 |  |  |  |  | # we often sort numerically, so a helper func for readability
69 |  |  |  |  | sub numerically {$a <=> $b}
70 |  |  |  |  |
71 |  |  |  |  | ###########################################
72 |  |  |  |  | # spent 378µs within Log::Log4perl::Level::import which was called 8 times, avg 47µs/call: # once (60µs+0s) by Log::Log4perl::BEGIN@13 at line 13 of Log/Log4perl.pm # once (57µs+0s) by Log::Log4perl::Appender::BEGIN@9 at line 9 of Log/Log4perl/Appender.pm # once (55µs+0s) by Log::Log4perl::Filter::BEGIN@9 at line 9 of Log/Log4perl/Filter.pm # once (43µs+0s) by Log::Log4perl::Filter::Boolean::BEGIN@10 at line 10 of Log/Log4perl/Filter/Boolean.pm # once (42µs+0s) by Log::Log4perl::Layout::SimpleLayout::BEGIN@11 at line 11 of Log/Log4perl/Layout/SimpleLayout.pm # once (42µs+0s) by Log::Log4perl::Layout::PatternLayout::BEGIN@14 at line 14 of Log/Log4perl/Layout/PatternLayout.pm # once (41µs+0s) by Log::Log4perl::Logger::BEGIN@10 at line 10 of Log/Log4perl/Logger.pm # once (39µs+0s) by Log::Log4perl::Config::BEGIN@9 at line 9 of Log/Log4perl/Config.pm sub import {
73 |  |  |  |  | ###########################################
74 | 24 | 59µs |  |  | my($class, $namespace) = @_;
75 |  |  |  |  |
76 | 8 | 7µs |  |  | if(defined $namespace) {
77 |  |  |  |  | # Export $OFF, $FATAL, $ERROR etc. to
78 |  |  |  |  | # the given namespace
79 |  |  |  |  | $namespace .= "::" unless $namespace =~ /::$/;
80 |  |  |  |  | } else {
81 |  |  |  |  | # Export $OFF, $FATAL, $ERROR etc. to
82 |  |  |  |  | # the caller's namespace
83 |  |  |  |  | $namespace = caller(0) . "::";
84 |  |  |  |  | }
85 |  |  |  |  |
86 |  |  |  |  | for my $key (keys %PRIORITY) {
87 | 384 | 333µs |  |  | my $name = "$namespace$key";
88 |  |  |  |  | my $value = $PRIORITY{$key};
89 |  |  |  |  | *{"$name"} = \$value;
90 |  |  |  |  | my $nameint = "$namespace${key}_INT";
91 |  |  |  |  | my $func = uc($key) . "_INT";
92 |  |  |  |  | *{"$nameint"} = \&$func;
93 |  |  |  |  | }
94 |  |  |  |  | }
95 |  |  |  |  |
96 |  |  |  |  | ##################################################
97 |  |  |  |  | sub new {
98 |  |  |  |  | ##################################################
99 |  |  |  |  | # We don't need any of this class nonsense
100 |  |  |  |  | # in Perl, because we won't allow subclassing
101 |  |  |  |  | # from this. We're optimizing for raw speed.
102 |  |  |  |  | }
103 |  |  |  |  |
104 |  |  |  |  | ##################################################
105 |  |  |  |  | sub to_priority {
106 |  |  |  |  | # changes a level name string to a priority numeric
107 |  |  |  |  | ##################################################
108 |  |  |  |  | my($string) = @_;
109 |  |  |  |  |
110 |  |  |  |  | if(exists $PRIORITY{$string}) {
111 |  |  |  |  | return $PRIORITY{$string};
112 |  |  |  |  | }else{
113 |  |  |  |  | croak "level '$string' is not a valid error level (".join ('|', keys %PRIORITY),')';
114 |  |  |  |  | }
115 |  |  |  |  | }
116 |  |  |  |  |
117 |  |  |  |  | ##################################################
118 |  |  |  |  | sub to_level {
119 |  |  |  |  | # changes a priority numeric constant to a level name string
120 |  |  |  |  | ##################################################
121 |  |  |  |  | my ($priority) = @_;
122 |  |  |  |  | if (exists $LEVELS{$priority}) {
123 |  |  |  |  | return $LEVELS{$priority}
124 |  |  |  |  | }else {
125 |  |  |  |  | croak("priority '$priority' is not a valid error level number (",
126 |  |  |  |  | join("|", sort numerically keys %LEVELS), "
127 |  |  |  |  | )");
128 |  |  |  |  | }
129 |  |  |  |  |
130 |  |  |  |  | }
131 |  |  |  |  |
132 |  |  |  |  | ##################################################
133 |  |  |  |  | sub to_LogDispatch_string {
134 |  |  |  |  | # translates into strings that Log::Dispatch recognizes
135 |  |  |  |  | ##################################################
136 |  |  |  |  | my($priority) = @_;
137 |  |  |  |  |
138 |  |  |  |  | confess "do what? no priority?" unless defined $priority;
139 |  |  |  |  |
140 |  |  |  |  | my $string;
141 |  |  |  |  |
142 |  |  |  |  | if(exists $LEVELS{$priority}) {
143 |  |  |  |  | $string = $LEVELS{$priority};
144 |  |  |  |  | }
145 |  |  |  |  |
146 |  |  |  |  | # Log::Dispatch idiosyncrasies
147 |  |  |  |  | if($priority == $PRIORITY{WARN}) {
148 |  |  |  |  | $string = "WARNING";
149 |  |  |  |  | }
150 |  |  |  |  |
151 |  |  |  |  | if($priority == $PRIORITY{FATAL}) {
152 |  |  |  |  | $string = "EMERGENCY";
153 |  |  |  |  | }
154 |  |  |  |  |
155 |  |  |  |  | return $string;
156 |  |  |  |  | }
157 |  |  |  |  |
158 |  |  |  |  | ###################################################
159 |  |  |  |  | sub is_valid {
160 |  |  |  |  | ###################################################
161 |  |  |  |  | my $q = shift;
162 |  |  |  |  |
163 |  |  |  |  | if ($q =~ /[A-Z]/) {
164 |  |  |  |  | return exists $PRIORITY{$q};
165 |  |  |  |  | }else{
166 |  |  |  |  | return $LEVELS{$q};
167 |  |  |  |  | }
168 |  |  |  |  |
169 |  |  |  |  | }
170 |  |  |  |  |
171 |  |  |  |  | sub get_higher_level {
172 |  |  |  |  | my ($old_priority, $delta) = @_;
173 |  |  |  |  |
174 |  |  |  |  | $delta ||= 1;
175 |  |  |  |  |
176 |  |  |  |  | my $new_priority = 0;
177 |  |  |  |  |
178 |  |  |  |  | foreach (1..$delta){
179 |  |  |  |  | #so the list is TRACE, DEBUG, INFO, WARN, ERROR, FATAL
180 |  |  |  |  | # but remember, the numbers go in reverse order!
181 |  |  |  |  | foreach my $p (sort numerically keys %LEVELS){
182 |  |  |  |  | if ($p > $old_priority) {
183 |  |  |  |  | $new_priority = $p;
184 |  |  |  |  | last;
185 |  |  |  |  | }
186 |  |  |  |  | }
187 |  |  |  |  | $old_priority = $new_priority;
188 |  |  |  |  | }
189 |  |  |  |  | return $new_priority;
190 |  |  |  |  | }
191 |  |  |  |  |
192 |  |  |  |  | sub get_lower_level {
193 |  |  |  |  | my ($old_priority, $delta) = @_;
194 |  |  |  |  |
195 |  |  |  |  | $delta ||= 1;
196 |  |  |  |  |
197 |  |  |  |  | my $new_priority = 0;
198 |  |  |  |  |
199 |  |  |  |  | foreach (1..$delta){
200 |  |  |  |  | #so the list is FATAL, ERROR, WARN, INFO, DEBUG, TRACE
201 |  |  |  |  | # but remember, the numbers go in reverse order!
202 |  |  |  |  | foreach my $p (reverse sort numerically keys %LEVELS){
203 |  |  |  |  | if ($p < $old_priority) {
204 |  |  |  |  | $new_priority = $p;
205 |  |  |  |  | last;
206 |  |  |  |  | }
207 |  |  |  |  | }
208 |  |  |  |  | $old_priority = $new_priority;
209 |  |  |  |  | }
210 |  |  |  |  | return $new_priority;
211 |  |  |  |  | }
212 |  |  |  |  |
213 |  |  |  |  | # spent 14µs within Log::Log4perl::Level::isGreaterOrEqual which was called 8 times, avg 2µs/call: # 8 times (14µs+0s) by Log::Log4perl::Logger::set_output_methods at line 213 of Log/Log4perl/Logger.pm, avg 2µs/call sub isGreaterOrEqual {
214 | 24 | 21µs |  |  | my $lval = shift;
215 |  |  |  |  | my $rval = shift;
216 |  |  |  |  |
217 |  |  |  |  | # in theory, we should check if the above really ARE valid levels.
218 |  |  |  |  | # but we just use numeric comparison, since they aren't really classes.
219 |  |  |  |  |
220 |  |  |  |  | # oh, yeah, and 'cuz level ints go from 0 .. N with 0 being highest,
221 |  |  |  |  | # these are reversed.
222 |  |  |  |  | return $lval <= $rval;
223 |  |  |  |  | }
224 |  |  |  |  |
225 |  |  |  |  | ######################################################################
226 |  |  |  |  | #
227 |  |  |  |  | # since the integer representation of levels is reversed from what
228 |  |  |  |  | # we normally want, we don't want to use < and >... instead, we
229 |  |  |  |  | # want to use this comparison function
230 |  |  |  |  |
231 |  |  |  |  |
232 | 1 | 9µs |  |  | 1;
233 |  |  |  |  |
234 |  |  |  |  | __END__