Module: ZTK::Profiler::Core
  
  
  
  
  
    
  
    
  
  
    - Included in:
- ZTK::Profiler
- Defined in:
- lib/ztk/profiler/core.rb
Overview
  
    Profiler Core Functionality
   
 
  
  
    
      Instance Method Summary
      (collapse)
    
    
  
  Dynamic Method Handling
  
    This class handles dynamic methods through the method_missing method
    
  
  
    
  
  
    - (Object) method_missing(method_name, *method_args) 
  
  
  
  
    | 
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55 | # File 'lib/ztk/profiler/core.rb', line 34
def method_missing(method_name, *method_args)
  raise "You must supply a block to the profiler method #{method_name.inspect}!" unless block_given?
  @@start_time ||= Time.now.utc
  result    = nil
  exception = nil
  timer     = Timer.new(method_name, @@timer_stack.last)
  @@timer_stack.push(timer)
  timer.benchmark = ::Benchmark.realtime do
    begin
      result = yield
    rescue Exception => exception
    end
  end
  @@timer_stack.pop
  exception.nil? or raise exception
  result
end | 
 
  
 
  
    Instance Method Details
    
      
  
  
    - (Object) report(options = {}) 
  
  
  
  
    | 
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83 | # File 'lib/ztk/profiler/core.rb', line 66
def report(options={})
  results = Array.new
  options = Base.build_config({}, options)
  stop
  if (Timer.count > 0)
    report_timers(options) and options.ui.stdout.puts
    results << report_timer_totals(options)
    results.last and options.ui.stdout.puts
    results << report_totals(options)
  else
    options.ui.stderr.puts("Nothing was profiled!")
    results = [ nil, nil ]
  end
  results
end | 
 
    
      
  
  
    - (Object) reset 
  
  
  
  
    | 
25
26
27
28
29
30
31
32 | # File 'lib/ztk/profiler/core.rb', line 25
def reset
  @@start_time  = nil
  @@end_time    = nil
  @@timer_stack = Array.new
  Timer.reset
  true
end | 
 
    
      
  
  
    - (Object) start 
  
  
  
  
    | 
12
13
14
15
16
17 | # File 'lib/ztk/profiler/core.rb', line 12
def start
  reset
  @@start_time  = Time.now.utc
  true
end | 
 
    
      
  
  
    - (Object) stop 
  
  
  
  
    | 
19
20
21
22
23 | # File 'lib/ztk/profiler/core.rb', line 19
def stop
  @@end_time ||= Time.now.utc
  true
end | 
 
    
      
  
  
    - (Object) total_time 
  
  
  
  
    | 
57
58
59
60
61
62
63
64 | # File 'lib/ztk/profiler/core.rb', line 57
def total_time
  if @@start_time.nil?
    raise ProfilerError, "You must start the profiler in order to calculate a total time!"
  else
    stop
    @@end_time - @@start_time
  end
end |