Sha256: bb0d095bef13cca51359bd5457ac5cb7e5d443f27060c1dd44fd9dc04f3f5bf1

Contents?: true

Size: 1.34 KB

Versions: 35

Compression:

Stored size: 1.34 KB

Contents

module Middleman
  module Profiling

    # The profiler instance. There can only be one!
    def self.profiler=(prof)
      @profiler = prof
    end
    def self.profiler
      @profiler ||= NullProfiler.new
    end

    # Start the profiler
    def self.start
      profiler.start
    end

    # Stop the profiler and generate a report. Make sure to call start first
    def self.report(report_name)
      profiler.report(report_name)
    end

    # A profiler that does nothing. The default.
    class NullProfiler
      def start
      end

      def report(report_name)
      end
    end

    # A profiler that uses ruby-prof
    class RubyProfProfiler
      def initialize
        begin
          require 'ruby-prof'
        rescue LoadError
          raise "To use the --profile option, you must 'gem install ruby-prof' (and include it in your Gemfile if running under bundle exec)"
        end
      end

      def start
        RubyProf.start
      end

      def report(report_name)
        result = RubyProf.stop

        printer = RubyProf::GraphHtmlPrinter.new(result)
        outfile = File.join("profile", report_name)
        outfile = (outfile + '.html') unless outfile.end_with? '.html'
        FileUtils.mkdir_p(File.dirname(outfile))
        File.open(outfile, 'w') do |f|
          printer.print(f, :min_percent=> 1)
        end
      end
    end
  end
end

Version data entries

35 entries across 35 versions & 2 rubygems

Version Path
middleman-core-x86-mingw32-3.0.14 lib/middleman-core/profiling.rb
middleman-core-3.0.14 lib/middleman-core/profiling.rb
middleman-core-x86-mingw32-3.0.13 lib/middleman-core/profiling.rb
middleman-core-3.0.13 lib/middleman-core/profiling.rb
middleman-core-x86-mingw32-3.0.12 lib/middleman-core/profiling.rb
middleman-core-3.0.12 lib/middleman-core/profiling.rb
middleman-core-x86-mingw32-3.0.12.pre.1 lib/middleman-core/profiling.rb
middleman-core-3.0.12.pre.1 lib/middleman-core/profiling.rb
middleman-core-x86-mingw32-3.0.11 lib/middleman-core/profiling.rb
middleman-core-3.0.11 lib/middleman-core/profiling.rb
middleman-core-x86-mingw32-3.0.10 lib/middleman-core/profiling.rb
middleman-core-x86-mingw32-3.0.10.pre.1 lib/middleman-core/profiling.rb
middleman-core-3.0.10.pre.1 lib/middleman-core/profiling.rb
middleman-core-x86-mingw32-3.0.9 lib/middleman-core/profiling.rb
middleman-core-3.0.9 lib/middleman-core/profiling.rb
middleman-core-x86-mingw32-3.0.8 lib/middleman-core/profiling.rb
middleman-core-3.0.8 lib/middleman-core/profiling.rb
middleman-core-x86-mingw32-3.0.8.pre.2 lib/middleman-core/profiling.rb
middleman-core-3.0.8.pre.2 lib/middleman-core/profiling.rb
middleman-core-x86-mingw32-3.0.8.pre.1 lib/middleman-core/profiling.rb