Class: ZTK::Profiler

Inherits:
Object
  • Object
show all
Extended by:
Core, Private
Defined in:
lib/ztk/profiler.rb,
lib/ztk/profiler/core.rb,
lib/ztk/profiler/timer.rb,
lib/ztk/profiler/private.rb,
lib/ztk/profiler/timer/class_methods.rb

Overview

Profiler Class

A comprehensive timing profiler, this class functions using method_missing to allow the consumer to define timing profiles in an ad hoc manner using a block.

Examples:

Nested profiling


ZTK::Profiler.reset

ZTK::Profiler.operation_alpha do
  ZTK::Profiler.operation_one do
    ZTK::Profiler.operation_a do
      sleep(0.1)
    end
    ZTK::Profiler.operation_b do
      sleep(0.1)
    end
    ZTK::Profiler.operation_c do
      sleep(0.1)
    end
  end
  ZTK::Profiler.operation_two do
    ZTK::Profiler.operation_d do
      sleep(0.1)
    end
    ZTK::Profiler.operation_e do
      sleep(0.1)
    end
    ZTK::Profiler.operation_f do
      sleep(0.1)
    end
  end
end
ZTK::Profiler.operation_beta do
  ZTK::Profiler.operation_three do
    ZTK::Profiler.operation_a do
      sleep(0.1)
    end
    ZTK::Profiler.operation_b do
      sleep(0.1)
    end
    ZTK::Profiler.operation_c do
      sleep(0.1)
    end
  end
end

ZTK::Profiler.report

Report output


--+ OperationAlpha 0.6070s
  |--+ OperationOne 0.3035s
  |  |--+ OperationA 0.1011s
  |  |--+ OperationB 0.1011s
  |  |--+ OperationC 0.1011s
  |--+ OperationTwo 0.3035s
  |  |--+ OperationD 0.1011s
  |  |--+ OperationE 0.1011s
  |  |--+ OperationF 0.1011s
--+ OperationBeta 0.3034s
  |--+ OperationThree 0.3034s
  |  |--+ OperationA 0.1011s
  |  |--+ OperationB 0.1011s
  |  |--+ OperationC 0.1011s

 OperationAlpha: 0.6070s (22.2%)
   OperationOne: 0.3035s (11.1%)
     OperationA: 0.2022s (7.4%)
     OperationB: 0.2022s (7.4%)
     OperationC: 0.2022s (7.4%)
   OperationTwo: 0.3035s (11.1%)
     OperationD: 0.1011s (3.7%)
     OperationE: 0.1011s (3.7%)
     OperationF: 0.1011s (3.7%)
  OperationBeta: 0.3034s (11.1%)
 OperationThree: 0.3034s (11.1%)

   Nested Time: 2.7306s
   Actual Time: 0.9110s
 Profiled Time: 0.9105s
  Missing Time: 0.0005s

Author:

Defined Under Namespace

Modules: Core, Private Classes: Timer

Method Summary

Methods included from Private

report_timer_totals, report_timers, report_totals

Methods included from Core

method_missing, report, reset, start, stop, total_time