NAME
Log::Timer - track nested timing information
VERSION
version 1.0.1
SYNOPSIS
use Log::Timer;
sub some_action {
my $sub_timer = subroutine_timer();
# do things
...
}
FUNCTIONS
timer
my $timer1 = timer('GET /foo');
my $timer2 = timer('update_all_things');
my $timer3 = timer('fetching data from DB', {
prefix => $request_url,
context => $request_id,
});
Start a timer. When the returned object gets destroyed, logs the time elapsed (at trace
level).
All timers with the same $message
contribute to a set of stats, see report_timing_stats
The prefix
is just added in front of the log message.
Timers started "inside" other timers will get logged indented, so that you can see the breakdown of any outer timings. If you need to capture several timer metrics at the same level, you can pass indent_increase => 0
after the first timer.
If you're running a set of asynchronous tasks, using the same context
for each logical task (using for example a request id) will ensure that the nested indenting makes sense.
subroutine_timer
my $timer1 = subroutine_timer();
my $timer2 = subroutine_timer($message, {
prefix => $request_url,
context => $request_id,
depth => 2,
});
Same as "timer
", but the $message
is automatically prefixed with the name of the current subroutine. You can pass a depth
option (defaults to 1) to pick a sub further up the call stack.
report_timing_stats
Log::Timer::report_timing_stats();
Logs (at info
level) some statistical information about the timers ran until now, grouped by message. Then clears the stored values.
This is also called automatically at END
time.
clear_timing_stats
Log::Timer::clear_timing_stats();
Clears all values stored for statistical purposes.
AUTHORS
Johan Lindstrom <Johan.Lindstrom@broadbean.com>
Gianni Ceccarelli <gianni.ceccarelli@broadbean.com>
COPYRIGHT AND LICENSE
This software is copyright (c) 2019 by BroadBean UK, a CareerBuilder Company.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.