.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man v6.0.2 (Pod::Simple 3.45) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" Required to disable full justification in groff 1.23.0. .if n .ds AD l .\" ======================================================================== .\" .IX Title "Util::TimeTracker 3" .TH Util::TimeTracker 3 2026-08-14 "perl v5.42.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME Log::Log4perl::Util::TimeTracker \- Track time elapsed .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 1 \& use Log::Log4perl::Util::TimeTracker; \& \& my $timer = Log::Log4perl::Util::TimeTracker\->new(); \& \& # equivalent to Time::HiRes::gettimeofday(), regardless \& # if Time::HiRes is present or not. \& my($seconds, $microseconds) = $timer\->gettimeofday(); \& \& # reset internal timer \& $timer\->reset(); \& \& # return milliseconds since last reset \& $msecs = $timer\->milliseconds(); \& \& # return milliseconds since last call \& $msecs = $timer\->delta_milliseconds(); .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" This utility module helps tracking time elapsed for PatternLayout\*(Aqs date and time placeholders. Its accuracy depends on the availability of the Time::HiRes module. If it\*(Aqs available, its granularity is milliseconds, if not, seconds. .PP The most common use of this module is calling the \fBgettimeofday()\fR method: .PP .Vb 1 \& my($seconds, $microseconds) = $timer\->gettimeofday(); .Ve .PP It returns seconds and microseconds of the current epoch time. If Time::HiRes is installed, it will simply defer to its \fBgettimeofday()\fR function, if it\*(Aqs missing, \fBtime()\fR will be called instead and \f(CW$microseconds\fR will always be 0. .PP To measure time elapsed in milliseconds, use the \fBreset()\fR method to reset the timer to the current time, followed by one or more calls to the \fBmilliseconds()\fR method: .PP .Vb 2 \& # reset internal timer \& $timer\->reset(); \& \& # return milliseconds since last reset \& $msecs = $timer\->milliseconds(); .Ve .PP On top of the time span between the last reset and the current time, the module keeps track of the time between calls to \fBdelta_milliseconds()\fR: .PP .Vb 1 \& $msecs = $timer\->delta_milliseconds(); .Ve .PP On the first call, this will return the number of milliseconds since the last \fBreset()\fR, on subsequent calls, it will return the time elapsed in milliseconds since the last call to \fBdelta_milliseconds()\fR instead. Note that \fBreset()\fR also resets the time of the last call. .PP The internal timer of this module gets its time input from the POSIX \fBtime()\fR function, or, if the Time::HiRes module is available, from its \&\fBgettimeofday()\fR function. To figure out which one it is, use .PP .Vb 5 \& if( $timer\->hires_available() ) { \& print "Hooray, we get real milliseconds!\en"; \& } else { \& print "Milliseconds are just bogus\en"; \& } .Ve .PP For testing purposes, a different time source can be provided, so test suites can simulate time passing by without actually having to wait: .PP .Vb 1 \& my $start_time = time(); \& \& my $timer = Log::Log4perl::Util::TimeTracker\->new( \& time_function => sub { \& return $start_time++; \& }, \& ); .Ve .PP Every call to \f(CW$timer\fR\->\fBepoch()\fR will then return a time value that is one second ahead of the value returned on the previous call. This also means that every call to \fBdelta_milliseconds()\fR will return a value that exceeds the value returned on the previous call by 1000. .SH LICENSE .IX Header "LICENSE" Copyright 2002\-2026 by Mike Schilli and Kevin Goess . .PP This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.