Sha256: fd422f530c3cea3c1be5a6eea6b36aae82ca2b7f335593a67720c78cbd3304f7

Contents?: true

Size: 1.1 KB

Versions: 6

Compression:

Stored size: 1.1 KB

Contents

require 'ruby-prof'

module DRbQS
  module Test
    class Prof
      PRINTER_TYPE = [:flat, :graph, :graphhtml, :calltree]

      # :flat
      # :graph
      # :graphhtml
      # :calltree
      def initialize(printer_type, output)
        @printer_type = printer_type
        unless PRINTER_TYPE.include?(@printer_type)
          raise "Invalid printer type: #{@printer_type.inspect}"
        end
        @output = output
      end

      def get_printer(result)
        case @printer_type
        when :flat
          RubyProf::FlatPrinter.new(result)
        when :graph
          RubyProf::GraphPrinter.new(result)
        when :graphhtml
          RubyProf::GraphHtmlPrinter.new(result)
        when :calltree
          RubyProf::CallTreePrinter.new(result)
        end
      end
      private :get_printer

      def start
        RubyProf.start
      end

      def finish
        printer = get_printer(RubyProf.stop)
        if IO === @output
          printer.print(@output)
        else
          Kernel.open(@output, 'w') do |f|
            printer.print(f)
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
drbqs-0.1.1 lib/drbqs/server/test/prof.rb
drbqs-0.1.0 lib/drbqs/server/test/prof.rb
drbqs-0.0.19 lib/drbqs/server/test/prof.rb
drbqs-0.0.18 lib/drbqs/server/test/prof.rb
drbqs-0.0.17 lib/drbqs/server/test/prof.rb
drbqs-0.0.16 lib/drbqs/server/test/prof.rb