Class: Speedup::Collectors::RubyprofCollector

Inherits:
Collector
  • Object
show all
Defined in:
lib/speedup/collectors/rubyprof_collector.rb

Instance Method Summary collapse

Methods inherited from Collector

#context_id, #dom_id, #enabled?, #event_to_data, key, #key, #register, #render?, #store_event, #subscribe

Constructor Details

#initialize(options = {}) ⇒ RubyprofCollector

Returns a new instance of RubyprofCollector.



5
6
7
8
9
10
# File 'lib/speedup/collectors/rubyprof_collector.rb', line 5

def initialize(options={})
  require 'ruby-prof'
  @results_dir = Rails.root.join('tmp', 'rubyprof')
  Dir.mkdir( @results_dir ) unless File.directory?(@results_dir)
  super
end

Instance Method Details

#end_prof(result_id = nil) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/speedup/collectors/rubyprof_collector.rb', line 44

def end_prof(result_id=nil)
  result = RubyProf.stop

  Speedup.request.store_event(key, result_id )

  # Print a flat profile to text
  printer = printer_klass.new(result)
  ::File.open(@results_dir.join( Speedup.request.id + result_id.to_s + '.html' ), 'wb') do |file|
    printer.print(file)
  end
end

#filter_event?(evt) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/speedup/collectors/rubyprof_collector.rb', line 36

def filter_event?(evt)
  super || evt.payload[:controller].start_with?('Speedup')
end

#parse_optionsObject



12
13
14
# File 'lib/speedup/collectors/rubyprof_collector.rb', line 12

def parse_options
  @profile_request = !!@options[:profile_request]
end

#profile(result_id = nil, &block) ⇒ Object



56
57
58
59
60
# File 'lib/speedup/collectors/rubyprof_collector.rb', line 56

def profile(result_id=nil, &block)
  start_prof
  yield
  end_prof(next_id)
end

#resultsObject

The data results that are inserted at the end of the request for use in deferred placeholders in the Peek the bar.

Returns Hash.



20
21
22
# File 'lib/speedup/collectors/rubyprof_collector.rb', line 20

def results
  {}
end

#setup_subscribesObject



24
25
26
27
28
29
30
31
32
33
# File 'lib/speedup/collectors/rubyprof_collector.rb', line 24

def setup_subscribes
  if enabled? && @profile_request
    before_request do
      start_prof
    end
    after_request do
      end_prof
    end
  end
end

#start_profObject



40
41
42
# File 'lib/speedup/collectors/rubyprof_collector.rb', line 40

def start_prof
  RubyProf.start
end