Sha256: 079e2dbe75d81c9dff519273f002cf4ada433864977eaf156c96d8a097bbadb7

Contents?: true

Size: 1.89 KB

Versions: 29

Compression:

Stored size: 1.89 KB

Contents

# encoding: utf-8

module RubyProf
  # Generates flat[link:files/examples/flat_txt.html] profile reports as text.
  # To use the flat printer:
  #
  #   result = RubyProf.profile do
  #     [code to profile]
  #   end
  #
  #   printer = RubyProf::FlatPrinter.new(result)
  #   printer.print(STDOUT, {})
  #
  class FlatPrinter < AbstractPrinter
    # Override for this printer to sort by self time by default
    def sort_method
      @options[:sort_method] || :self_time
    end

    private

    def print_column_headers
      @output << " %self      total      self      wait     child     calls  name                           location\n"
    end

    def print_methods(thread)
      total_time = thread.total_time
      methods = thread.methods.sort_by(&sort_method).reverse

      sum = 0
      methods.each do |method|
        percent = (method.send(filter_by) / total_time) * 100
        next if percent < min_percent
        next if percent > max_percent

        sum += method.self_time
        #self_time_called = method.called > 0 ? method.self_time/method.called : 0
        #total_time_called = method.called > 0? method.total_time/method.called : 0

        @output << "%6.2f  %9.3f %9.3f %9.3f %9.3f %8d  %s%-30s %s\n" % [
                      method.self_time / total_time * 100, # %self
                      method.total_time,                   # total
                      method.self_time,                    # self
                      method.wait_time,                    # wait
                      method.children_time,                # children
                      method.called,                       # calls
                      method.recursive? ? "*" : " ",       # cycle
                      method.full_name,                    # method_name]
                      method_location(method)]             # location]
      end
    end
  end
end

Version data entries

29 entries across 29 versions & 2 rubygems

Version Path
ruby-prof-1.7.1-x64-mingw-ucrt lib/ruby-prof/printers/flat_printer.rb
ruby-prof-1.7.1 lib/ruby-prof/printers/flat_printer.rb
ruby-prof-1.7.0-x64-mingw-ucrt lib/ruby-prof/printers/flat_printer.rb
ruby-prof-1.7.0 lib/ruby-prof/printers/flat_printer.rb
honeybadger-5.4.0 vendor/bundle/ruby/3.2.0/gems/ruby-prof-1.6.3/lib/ruby-prof/printers/flat_printer.rb
honeybadger-5.3.0 vendor/bundle/ruby/3.2.0/gems/ruby-prof-1.6.3/lib/ruby-prof/printers/flat_printer.rb
ruby-prof-1.6.3-x64-mingw-ucrt lib/ruby-prof/printers/flat_printer.rb
ruby-prof-1.6.3 lib/ruby-prof/printers/flat_printer.rb
ruby-prof-1.6.2-x64-mingw-ucrt lib/ruby-prof/printers/flat_printer.rb
ruby-prof-1.6.2 lib/ruby-prof/printers/flat_printer.rb
ruby-prof-1.6.1 lib/ruby-prof/printers/flat_printer.rb
ruby-prof-1.6.1-x64-mingw-ucrt lib/ruby-prof/printers/flat_printer.rb
ruby-prof-1.5.0-x64-mingw-ucrt lib/ruby-prof/printers/flat_printer.rb
ruby-prof-1.5.0 lib/ruby-prof/printers/flat_printer.rb
ruby-prof-1.4.5-x64-mingw-ucrt lib/ruby-prof/printers/flat_printer.rb
ruby-prof-1.4.5 lib/ruby-prof/printers/flat_printer.rb
ruby-prof-1.4.4-x64-mingw-ucrt lib/ruby-prof/printers/flat_printer.rb
ruby-prof-1.4.4 lib/ruby-prof/printers/flat_printer.rb
ruby-prof-1.4.3-x64-mingw32 lib/ruby-prof/printers/flat_printer.rb
ruby-prof-1.4.3 lib/ruby-prof/printers/flat_printer.rb