Module: ZTK::Profiler::Timer::ClassMethods

Included in:
ZTK::Profiler::Timer
Defined in:
lib/ztk/profiler/timer/class_methods.rb

Overview

Profiler Timer Class Functionality

Instance Method Summary (collapse)

Instance Method Details

- (Object) add(timer)



26
27
28
29
30
31
32
33
# File 'lib/ztk/profiler/timer/class_methods.rb', line 26

def add(timer)
  @@timers << timer

  @@timers_by_parent[timer.parent] << timer
  @@timers_by_name[timer.name] << timer

  true
end

- (Object) benchmark_nested_total



66
67
68
69
# File 'lib/ztk/profiler/timer/class_methods.rb', line 66

def benchmark_nested_total
  @@benchmark_nested_total ||= @@timers.map(&:benchmark_nested).reduce(&:+)
  @@benchmark_nested_total
end

- (Object) benchmark_total



61
62
63
64
# File 'lib/ztk/profiler/timer/class_methods.rb', line 61

def benchmark_total
  @@benchmark_total ||= @@timers.map(&:benchmark).reduce(&:+)
  @@benchmark_total
end

- (Object) count



57
58
59
# File 'lib/ztk/profiler/timer/class_methods.rb', line 57

def count
  @@timers.count
end

- (Object) nested_time(name = nil, parent = nil)



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/ztk/profiler/timer/class_methods.rb', line 43

def nested_time(name=nil, parent=nil)
  result = 0.0

  child_timers = @@timers_by_parent[parent]
  child_timers.each do |child_timer|
    if (child_timer.name == name)
      result += child_timer.benchmark_nested
    end
    result += nested_time(name, child_timer)
  end

  result
end

- (Object) reset



35
36
37
38
39
40
41
# File 'lib/ztk/profiler/timer/class_methods.rb', line 35

def reset
  @@timers           = Array.new
  @@timers_by_name   = Hash.new { |hash, key| hash[key] = Array.new }
  @@timers_by_parent = Hash.new { |hash, key| hash[key] = Array.new }

  true
end

- (Object) timers



14
15
16
# File 'lib/ztk/profiler/timer/class_methods.rb', line 14

def timers
  @@timers
end

- (Object) timers_by_name



22
23
24
# File 'lib/ztk/profiler/timer/class_methods.rb', line 22

def timers_by_name
  @@timers_by_name
end

- (Object) timers_by_parent



18
19
20
# File 'lib/ztk/profiler/timer/class_methods.rb', line 18

def timers_by_parent
  @@timers_by_parent
end

- (Object) total_time



71
72
73
74
# File 'lib/ztk/profiler/timer/class_methods.rb', line 71

def total_time
  @@total_time ||= @@timers_by_parent[nil].map(&:benchmark).reduce(&:+)
  @@total_time
end