Class: Corn::Profiler

Inherits:
Object
  • Object
show all
Defined in:
lib/corn/profiler.rb

Instance Method Summary collapse

Constructor Details

#initialize(post_interval, sampling_interval) ⇒ Profiler

Returns a new instance of Profiler.



6
7
8
9
10
# File 'lib/corn/profiler.rb', line 6

def initialize(post_interval, sampling_interval)
  @post = Post.new(post_interval)
  @prof = SamplingProf.new(sampling_interval)
  at_exit { terminate }
end

Instance Method Details

#profile(handler, &block) ⇒ Object



12
13
14
# File 'lib/corn/profiler.rb', line 12

def profile(handler, &block)
  @prof.profile(lambda {|data| @post.enqueue(handler.call(data))}, &block)
end

#terminateObject



16
17
18
19
# File 'lib/corn/profiler.rb', line 16

def terminate
  @prof.terminate rescue nil
  @post.terminate rescue nil
end