The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.


Log::Timer - track nested timing information


version 1.0.1


  use Log::Timer;

  sub some_action {
      my $sub_timer = subroutine_timer();
      # do things



  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.


  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.



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.



Clears all values stored for statistical purposes.


  • Johan Lindstrom <>

  • Gianni Ceccarelli <>


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.