Module: ZTK::Profiler::Private

Included in:
ZTK::Profiler
Defined in:
lib/ztk/profiler/private.rb

Overview

Profiler Private Functionality

Instance Method Summary (collapse)

Instance Method Details

- (Object) report_timer_totals(options = {})



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/ztk/profiler/private.rb', line 22

def report_timer_totals(options={})
  return false if (Timer.count == 0)

  result                = Hash.new
  timer_names           = Timer.timers_by_name.keys.compact
  timer_names_camelize  = timer_names.map(&:to_s).map(&:camelize)
  max_timer_name_length = (timer_names_camelize.map(&:length).max + 1)
  timer_names.each do |timer_name|
    benchmark_nested   = Timer.timers_by_name[timer_name].map(&:benchmark_nested).reduce(&:+)
    result[timer_name] = benchmark_nested

    options.ui.stdout.print("%#{max_timer_name_length}s: %0.4fs (%-3.1f%%)\n" % [timer_name.to_s.camelize, benchmark_nested, (benchmark_nested / Timer.benchmark_nested_total) * 100])
  end
  result
end

- (Object) report_timers(options = {}, parent = nil, depth = 0)



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/ztk/profiler/private.rb', line 7

def report_timers(options={}, parent=nil, depth=0)
  return false if (Timer.count == 0)

  child_timers = Timer.timers_by_parent[parent]
  child_timers.each do |timer|
    prefix = ('  |' * (depth))

    options.ui.stdout.print("%s--+ %s %0.4fs\n" % [ prefix, timer.name.to_s.camelize, timer.benchmark ])

    report_timers(options, timer, (depth + 1))
  end

  true
end

- (Object) report_totals(options = {})



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/ztk/profiler/private.rb', line 38

def report_totals(options={})
  return false if (Timer.count == 0)

  times = {
    'Nested Time'   => Timer.benchmark_nested_total,
    'Actual Time'   => Profiler.total_time,
    'Profiled Time' => Timer.total_time,
    'Missing Time'  => (Profiler.total_time - Timer.total_time)
  }
  max_key_length = (times.keys.map(&:length).max + 1)
  time_format    = "%#{max_key_length}s: %0.4fs\n"

  times.each do |name, time|
    options.ui.stdout.print(time_format % [ name, time ])
  end
end