Class: RubyProf::Result

Inherits:
Object
  • Object
show all
Defined in:
ext/ruby_prof/ruby_prof.c,
lib/ruby-prof/result.rb,
ext/ruby_prof/ruby_prof.c

Overview

The RubyProf::Result class is used to store the results of a profiling run. And instace of the class is returned from the methods RubyProf#stop and RubyProf#profile.

RubyProf::Result has one field, called threads, which is a hash table keyed on thread ID. For each thread id, the hash table stores another hash table that contains profiling information for each method called during the threads execution. That hash table is keyed on method name and contains RubyProf::MethodInfo objects.

Instance Method Summary collapse

Instance Method Details

#compute_minimalityObject

this method gets called internally when profiling is stopped. it determines for each call_info whether it is minimal: a call_info is minimal in a call tree if the call_info is not a descendant of a call_info of the same method



8
9
10
11
12
13
14
15
16
17
# File 'lib/ruby-prof/result.rb', line 8

def compute_minimality
  threads.each do |threadid, method_infos|
    root_methods = method_infos.select{|mi| mi.root?}
    root_methods.each do |mi|
      mi.call_infos.select{|ci| ci.root?}.each do |call_info_root|
        call_info_root.compute_minimality(Set.new)
      end
    end
  end
end

#dumpObject



31
32
33
34
35
36
37
38
# File 'lib/ruby-prof/result.rb', line 31

def dump
  threads.each do |thread_id, methods|
    $stderr.puts "Call Info Dump for thread id #{thread_id}"
    methods.each do |method_info|
      $stderr.puts method_info.dump
    end
  end
end

#eliminate_methods!(matchers) ⇒ Object

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.



21
22
23
24
25
26
27
28
29
# File 'lib/ruby-prof/result.rb', line 21

def eliminate_methods!(matchers)
  matchers = read_regexps_from_file(matchers) if matchers.is_a?(String)
  eliminated = []
  threads.each do |thread_id, methods|
    matchers.each{ |matcher| eliminated.concat(eliminate_methods(methods, matcher)) }
  end
  compute_minimality # is this really necessary?
  eliminated
end

#threadsHash

Returns a hash table keyed on thread ID. For each thread id, the hash table stores another hash table that contains profiling information for each method called during the threads execution. That hash table is keyed on method name and contains RubyProf::MethodInfo objects.

Returns:

  • (Hash)


1347
1348
1349
1350
1351
1352
# File 'ext/ruby_prof/ruby_prof.c', line 1347

static VALUE
prof_result_threads(VALUE self)
{
    prof_result_t *prof_result = get_prof_result(self);
    return prof_result->threads;
}