Sha256: b0448b465f6203b39527546ed2f14627d0e5d71ade0ea17258e45a2832ef505c

Contents?: true

Size: 1.05 KB

Versions: 2

Compression:

Stored size: 1.05 KB

Contents

module Speedup
  module Collectors
    class RubyprofCollector < Collector

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

      def parse_options
        # pass
      end

      # The data results that are inserted at the end of the request for use in
      # deferred placeholders in the Peek the bar.
      #
      # Returns Hash.
      def results
        {}
      end

      def setup_subscribes
        before_request do
          RubyProf.start if enabled?
        end
        after_request do
          result = RubyProf.stop if enabled?

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


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

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
speedup-rails-0.0.3 lib/speedup/collectors/rubyprof_collector.rb
speedup-rails-0.0.2 lib/speedup/collectors/rubyprof_collector.rb