Sha256: eb7bc0a383a7691f80dbd13978eb28d617b08953ad81c652cd095cade09d5b63

Contents?: true

Size: 1.6 KB

Versions: 5

Compression:

Stored size: 1.6 KB

Contents

# encoding: utf-8

require 'set'
module RubyProf
  class Profile
    # This method gets called once profiling has been completed
    # but before results are returned to the user.  Thus it provides
    # a hook to do any necessary post-processing on the call graph.
    def post_process
      self.threads.each do |thread|
        thread.detect_recursion
      end
    end

    # eliminate some calls from the graph by merging the information into callers.
    # matchers can be a list of strings or regular expressions or the name of a file containing regexps.
    def eliminate_methods!(matchers)
      matchers = read_regexps_from_file(matchers) if matchers.is_a?(String)
      eliminated = []
      threads.each do |thread|
        matchers.each{ |matcher| eliminated.concat(eliminate_methods(thread.methods, matcher)) }
      end
      eliminated
    end

    private

    # read regexps from file
    def read_regexps_from_file(file_name)
      matchers = []
      File.open(file_name).each_line do |l|
        next if (l =~ /^(#.*|\s*)$/) # emtpy lines and lines starting with #
        matchers << Regexp.new(l.strip)
      end
    end

    # eliminate methods matching matcher
    def eliminate_methods(methods, matcher)
      eliminated = []
      i = 0
      while i < methods.size
        method_info = methods[i]
        method_name = method_info.full_name
        if matcher === method_name
          raise "can't eliminate root method" if method_info.root?
          eliminated << methods.delete_at(i)
          method_info.eliminate!
        else
          i += 1
        end
      end
      eliminated
    end

  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/ruby-prof-0.15.9/lib/ruby-prof/profile.rb
ruby-prof-0.15.9 lib/ruby-prof/profile.rb
ruby-prof-0.15.8 lib/ruby-prof/profile.rb
ruby-prof-0.15.7 lib/ruby-prof/profile.rb
ruby-prof-0.15.6 lib/ruby-prof/profile.rb