Log::Timer - track nested timing information
version 1.0.1
use Log::Timer; sub some_action { my $sub_timer = subroutine_timer(); # do things ... }
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).
trace
All timers with the same $message contribute to a set of stats, see report_timing_stats
$message
report_timing_stats
The prefix is just added in front of the log message.
prefix
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.
indent_increase => 0
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.
context
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.
depth
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.
info
This is also called automatically at END time.
END
clear_timing_stats
Log::Timer::clear_timing_stats();
Clears all values stored for statistical purposes.
Johan Lindstrom <Johan.Lindstrom@broadbean.com>
Gianni Ceccarelli <gianni.ceccarelli@broadbean.com>
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.
To install Log::Timer, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Log::Timer
CPAN shell
perl -MCPAN -e shell install Log::Timer
For more information on module installation, please visit the detailed CPAN module installation guide.