Sha256: c0872a94effe533cce3e758c86119025eb9f4dc42c1e435d7d13780539c25987

Contents?: true

Size: 843 Bytes

Versions: 2

Compression:

Stored size: 843 Bytes

Contents

require "ruby-prof"

module Ramaze
  module Dispatcher
    class ActionProfiler < Action
      def self.process(path)
        if RubyProf.running?
          super
        else
          result = RubyProf.profile { super }
          output = StringIO.new
          printer = RubyProf::FlatPrinter.new(result)
          options = {
            :min_percent => Contrib::Profiling.trait[:min_percent],
            :print_file => false
          }
          printer.print(output, options)
          output.string.split("\n").each do |line|
            Log.info(line)
          end
        end
      end
    end
  end

  module Contrib
    class Profiling
      trait :min_percent => 1

      def self.startup
        Dispatcher::FILTER.delete(Dispatcher::Action)
        Dispatcher::FILTER << Dispatcher::ActionProfiler
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ramaze-0.3.9 lib/ramaze/contrib/profiling.rb
ramaze-0.3.9.1 lib/ramaze/contrib/profiling.rb