1Util::TimeTracker(3)  User Contributed Perl Documentation Util::TimeTracker(3)
2
3
4

NAME

6       Log::Log4perl::Util::TimeTracker - Track time elapsed
7

SYNOPSIS

9         use Log::Log4perl::Util::TimeTracker;
10
11         my $timer = Log::Log4perl::Util::TimeTracker->new();
12
13           # equivalent to Time::HiRes::gettimeofday(), regardless
14           # if Time::HiRes is present or not.
15         my($seconds, $microseconds) = $timer->gettimeofday();
16
17           # reset internal timer
18         $timer->reset();
19
20           # return milliseconds since last reset
21         $msecs = $timer->milliseconds();
22
23           # return milliseconds since last call
24         $msecs = $timer->delta_milliseconds();
25

DESCRIPTION

27       This utility module helps tracking time elapsed for PatternLayout's
28       date and time placeholders. Its accuracy depends on the availability of
29       the Time::HiRes module. If it's available, its granularity is
30       milliseconds, if not, seconds.
31
32       The most common use of this module is calling the gettimeofday()
33       method:
34
35         my($seconds, $microseconds) = $timer->gettimeofday();
36
37       It returns seconds and microseconds of the current epoch time. If
38       Time::HiRes is installed, it will simply defer to its gettimeofday()
39       function, if it's missing, time() will be called instead and
40       $microseconds will always be 0.
41
42       To measure time elapsed in milliseconds, use the reset() method to
43       reset the timer to the current time, followed by one or more calls to
44       the milliseconds() method:
45
46           # reset internal timer
47         $timer->reset();
48
49           # return milliseconds since last reset
50         $msecs = $timer->milliseconds();
51
52       On top of the time span between the last reset and the current time,
53       the module keeps track of the time between calls to
54       delta_milliseconds():
55
56         $msecs = $timer->delta_milliseconds();
57
58       On the first call, this will return the number of milliseconds since
59       the last reset(), on subsequent calls, it will return the time elapsed
60       in milliseconds since the last call to delta_milliseconds() instead.
61       Note that reset() also resets the time of the last call.
62
63       The internal timer of this module gets its time input from the POSIX
64       time() function, or, if the Time::HiRes module is available, from its
65       gettimeofday() function. To figure out which one it is, use
66
67           if( $timer->hires_available() ) {
68               print "Hooray, we get real milliseconds!\n";
69           } else {
70               print "Milliseconds are just bogus\n";
71           }
72
73       For testing purposes, a different time source can be provided, so test
74       suites can simulate time passing by without actually having to wait:
75
76         my $start_time = time();
77
78         my $timer = Log::Log4perl::Util::TimeTracker->new(
79                 time_function => sub {
80                     return $start_time++;
81                 },
82         );
83
84       Every call to $timer->epoch() will then return a time value that is one
85       second ahead of the value returned on the previous call. This also
86       means that every call to delta_milliseconds() will return a value that
87       exceeds the value returned on the previous call by 1000.
88

LICENSE

90       Copyright 2002-2013 by Mike Schilli <m@perlmeister.com> and Kevin Goess
91       <cpan@goess.org>.
92
93       This library is free software; you can redistribute it and/or modify it
94       under the same terms as Perl itself.
95

AUTHOR

97       Please contribute patches to the project on Github:
98
99           http://github.com/mschilli/log4perl
100
101       Send bug reports or requests for enhancements to the authors via our
102
103       MAILING LIST (questions, bug reports, suggestions/patches):
104       log4perl-devel@lists.sourceforge.net
105
106       Authors (please contact them via the list above, not directly): Mike
107       Schilli <m@perlmeister.com>, Kevin Goess <cpan@goess.org>
108
109       Contributors (in alphabetical order): Ateeq Altaf, Cory Bennett, Jens
110       Berthold, Jeremy Bopp, Hutton Davidson, Chris R. Donnelly, Matisse
111       Enzer, Hugh Esco, Anthony Foiani, James FitzGibbon, Carl Franks, Dennis
112       Gregorovic, Andy Grundman, Paul Harrington, Alexander Hartmaier  David
113       Hull, Robert Jacobson, Jason Kohles, Jeff Macdonald, Markus Peter,
114       Brett Rann, Peter Rabbitson, Erik Selberg, Aaron Straup Cope, Lars
115       Thegler, David Viner, Mac Yang.
116
117
118
119perl v5.32.1                      2021-02-08              Util::TimeTracker(3)
Impressum