Filename | /2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/Log/Log4perl/Util/TimeTracker.pm |
Statements | Executed 38 statements in 521µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 23µs | 23µs | BEGIN@5 | Log::Log4perl::Util::TimeTracker::
1 | 1 | 1 | 22µs | 59µs | new | Log::Log4perl::Util::TimeTracker::
1 | 1 | 1 | 9µs | 965µs | BEGIN@13 | Log::Log4perl::Util::TimeTracker::
1 | 1 | 1 | 9µs | 38µs | reset | Log::Log4perl::Util::TimeTracker::
1 | 1 | 1 | 8µs | 21µs | _gettimeofday | Log::Log4perl::Util::TimeTracker::
1 | 1 | 1 | 7µs | 29µs | gettimeofday | Log::Log4perl::Util::TimeTracker::
1 | 1 | 1 | 7µs | 9µs | BEGIN@6 | Log::Log4perl::Util::TimeTracker::
1 | 1 | 1 | 6µs | 47µs | BEGIN@9 | Log::Log4perl::Util::TimeTracker::
1 | 1 | 1 | 6µs | 14µs | BEGIN@7 | Log::Log4perl::Util::TimeTracker::
1 | 1 | 1 | 4µs | 4µs | BEGIN@8 | Log::Log4perl::Util::TimeTracker::
0 | 0 | 0 | 0s | 0s | delta_milliseconds | Log::Log4perl::Util::TimeTracker::
0 | 0 | 0 | 0s | 0s | hires_available | Log::Log4perl::Util::TimeTracker::
0 | 0 | 0 | 0s | 0s | milliseconds | Log::Log4perl::Util::TimeTracker::
0 | 0 | 0 | 0s | 0s | time_diff | Log::Log4perl::Util::TimeTracker::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | ################################################## | ||||
2 | package Log::Log4perl::Util::TimeTracker; | ||||
3 | ################################################## | ||||
4 | |||||
5 | 3 | 32µs | 1 | 23µs | # spent 23µs within Log::Log4perl::Util::TimeTracker::BEGIN@5 which was called:
# once (23µs+0s) by Log::Log4perl::Layout::PatternLayout::BEGIN@18 at line 5 # spent 23µs making 1 call to Log::Log4perl::Util::TimeTracker::BEGIN@5 |
6 | 3 | 18µs | 2 | 11µs | # spent 9µs (7+2) within Log::Log4perl::Util::TimeTracker::BEGIN@6 which was called:
# once (7µs+2µs) by Log::Log4perl::Layout::PatternLayout::BEGIN@18 at line 6 # spent 9µs making 1 call to Log::Log4perl::Util::TimeTracker::BEGIN@6
# spent 2µs making 1 call to strict::import |
7 | 3 | 17µs | 2 | 21µs | # spent 14µs (6+8) within Log::Log4perl::Util::TimeTracker::BEGIN@7 which was called:
# once (6µs+8µs) by Log::Log4perl::Layout::PatternLayout::BEGIN@18 at line 7 # spent 14µs making 1 call to Log::Log4perl::Util::TimeTracker::BEGIN@7
# spent 8µs making 1 call to warnings::import |
8 | 3 | 16µs | 1 | 4µs | # spent 4µs within Log::Log4perl::Util::TimeTracker::BEGIN@8 which was called:
# once (4µs+0s) by Log::Log4perl::Layout::PatternLayout::BEGIN@18 at line 8 # spent 4µs making 1 call to Log::Log4perl::Util::TimeTracker::BEGIN@8 |
9 | 3 | 53µs | 2 | 87µs | # spent 47µs (6+40) within Log::Log4perl::Util::TimeTracker::BEGIN@9 which was called:
# once (6µs+40µs) by Log::Log4perl::Layout::PatternLayout::BEGIN@18 at line 9 # spent 47µs making 1 call to Log::Log4perl::Util::TimeTracker::BEGIN@9
# spent 40µs making 1 call to Exporter::import |
10 | |||||
11 | 1 | 200ns | our $TIME_HIRES_AVAILABLE; | ||
12 | |||||
13 | # spent 965µs (9+956) within Log::Log4perl::Util::TimeTracker::BEGIN@13 which was called:
# once (9µs+956µs) by Log::Log4perl::Layout::PatternLayout::BEGIN@18 at line 22 | ||||
14 | # Check if we've got Time::HiRes. If not, don't make a big fuss, | ||||
15 | # just set a flag so we know later on that we can't have fine-grained | ||||
16 | # time stamps | ||||
17 | 1 | 300ns | $TIME_HIRES_AVAILABLE = 0; | ||
18 | 1 | 6µs | 1 | 956µs | if(Log::Log4perl::Util::module_available("Time::HiRes")) { # spent 956µs making 1 call to Log::Log4perl::Util::module_available |
19 | 1 | 500ns | require Time::HiRes; | ||
20 | 1 | 500ns | $TIME_HIRES_AVAILABLE = 1; | ||
21 | } | ||||
22 | 1 | 316µs | 1 | 965µs | } # spent 965µs making 1 call to Log::Log4perl::Util::TimeTracker::BEGIN@13 |
23 | |||||
24 | ################################################## | ||||
25 | # spent 59µs (22+38) within Log::Log4perl::Util::TimeTracker::new which was called:
# once (22µs+38µs) by Log::Log4perl::Layout::PatternLayout::new at line 60 of Log/Log4perl/Layout/PatternLayout.pm | ||||
26 | ################################################## | ||||
27 | 1 | 900ns | my $class = shift; | ||
28 | 1 | 500ns | $class = ref ($class) || $class; | ||
29 | |||||
30 | 1 | 3µs | my $self = { | ||
31 | reset_time => undef, | ||||
32 | @_, | ||||
33 | }; | ||||
34 | |||||
35 | 1 | 3µs | $self->{time_function} = \&_gettimeofday unless | ||
36 | defined $self->{time_function}; | ||||
37 | |||||
38 | 1 | 8µs | bless $self, $class; | ||
39 | |||||
40 | 1 | 3µs | 1 | 38µs | $self->reset(); # spent 38µs making 1 call to Log::Log4perl::Util::TimeTracker::reset |
41 | |||||
42 | 1 | 3µs | return $self; | ||
43 | } | ||||
44 | |||||
45 | ################################################## | ||||
46 | sub hires_available { | ||||
47 | ################################################## | ||||
48 | return $TIME_HIRES_AVAILABLE; | ||||
49 | } | ||||
50 | |||||
51 | ################################################## | ||||
52 | # spent 21µs (8+13) within Log::Log4perl::Util::TimeTracker::_gettimeofday which was called:
# once (8µs+13µs) by Log::Log4perl::Util::TimeTracker::gettimeofday at line 67 | ||||
53 | ################################################## | ||||
54 | # Return secs and optionally msecs if we have Time::HiRes | ||||
55 | 1 | 23µs | 1 | 13µs | if($TIME_HIRES_AVAILABLE) { # spent 13µs making 1 call to Time::HiRes::gettimeofday |
56 | return (Time::HiRes::gettimeofday()); | ||||
57 | } else { | ||||
58 | return (time(), 0); | ||||
59 | } | ||||
60 | } | ||||
61 | |||||
62 | ################################################## | ||||
63 | # spent 29µs (7+21) within Log::Log4perl::Util::TimeTracker::gettimeofday which was called:
# once (7µs+21µs) by Log::Log4perl::Util::TimeTracker::reset at line 78 | ||||
64 | ################################################## | ||||
65 | 1 | 600ns | my($self) = @_; | ||
66 | |||||
67 | 1 | 3µs | 1 | 21µs | my($seconds, $microseconds) = $self->{time_function}->(); # spent 21µs making 1 call to Log::Log4perl::Util::TimeTracker::_gettimeofday |
68 | |||||
69 | 1 | 400ns | $microseconds = 0 if ! defined $microseconds; | ||
70 | 1 | 3µs | return($seconds, $microseconds); | ||
71 | } | ||||
72 | |||||
73 | ################################################## | ||||
74 | # spent 38µs (9+29) within Log::Log4perl::Util::TimeTracker::reset which was called:
# once (9µs+29µs) by Log::Log4perl::Util::TimeTracker::new at line 40 | ||||
75 | ################################################## | ||||
76 | 1 | 700ns | my($self) = @_; | ||
77 | |||||
78 | 1 | 3µs | 1 | 29µs | my $current_time = [$self->gettimeofday()]; # spent 29µs making 1 call to Log::Log4perl::Util::TimeTracker::gettimeofday |
79 | 1 | 800ns | $self->{reset_time} = $current_time; | ||
80 | 1 | 600ns | $self->{last_call_time} = $current_time; | ||
81 | |||||
82 | 1 | 3µs | return $current_time; | ||
83 | } | ||||
84 | |||||
85 | ################################################## | ||||
86 | sub time_diff { | ||||
87 | ################################################## | ||||
88 | my($time_from, $time_to) = @_; | ||||
89 | |||||
90 | my $seconds = $time_to->[0] - | ||||
91 | $time_from->[0]; | ||||
92 | |||||
93 | my $milliseconds = int(( $time_to->[1] - | ||||
94 | $time_from->[1] ) / 1000); | ||||
95 | |||||
96 | if($milliseconds < 0) { | ||||
97 | $milliseconds = 1000 + $milliseconds; | ||||
98 | $seconds--; | ||||
99 | } | ||||
100 | |||||
101 | return($seconds, $milliseconds); | ||||
102 | } | ||||
103 | |||||
104 | ################################################## | ||||
105 | sub milliseconds { | ||||
106 | ################################################## | ||||
107 | my($self, $current_time) = @_; | ||||
108 | |||||
109 | $current_time = [ $self->gettimeofday() ] unless | ||||
110 | defined $current_time; | ||||
111 | |||||
112 | my($seconds, $milliseconds) = time_diff( | ||||
113 | $self->{reset_time}, | ||||
114 | $current_time); | ||||
115 | |||||
116 | return $seconds*1000 + $milliseconds; | ||||
117 | } | ||||
118 | |||||
119 | ################################################## | ||||
120 | sub delta_milliseconds { | ||||
121 | ################################################## | ||||
122 | my($self, $current_time) = @_; | ||||
123 | |||||
124 | $current_time = [ $self->gettimeofday() ] unless | ||||
125 | defined $current_time; | ||||
126 | |||||
127 | my($seconds, $milliseconds) = time_diff( | ||||
128 | $self->{last_call_time}, | ||||
129 | $current_time); | ||||
130 | |||||
131 | $self->{last_call_time} = $current_time; | ||||
132 | |||||
133 | return $seconds*1000 + $milliseconds; | ||||
134 | } | ||||
135 | |||||
136 | 1 | 3µs | 1; | ||
137 | |||||
138 | __END__ |