class RubyProf::Thread

The Thread class contains profile results for a single fiber (note a Ruby thread can run multiple fibers). You cannot create an instance of RubyProf::Thread, instead you access it from a RubyProf::Profile object.

profile = RubyProf::Profile.profile do
            ...
          end

profile.threads.each do |thread|
  thread.root_methods.sort.each do |method|
    puts method.total_time
  end
end

Public Instance Methods

fiber_id → number click to toggle source

Returns the fiber id of this thread.

static VALUE
prof_fiber_id(VALUE self)
{
    thread_data_t* thread = prof_get_thread(self);
    return thread->fiber_id;
}
id → number click to toggle source

Returns the thread id of this thread.

static VALUE
prof_thread_id(VALUE self)
{
    thread_data_t* thread = prof_get_thread(self);
    return thread->thread_id;
}
methods → [RubyProf::MethodInfo] click to toggle source

Returns an array of methods that were called from this thread during program execution.

static VALUE
prof_thread_methods(VALUE self)
{
    thread_data_t* thread = prof_get_thread(self);
    if (thread->methods == Qnil)
    {
        thread->methods = rb_ary_new();
        st_foreach(thread->method_table, collect_methods, thread->methods);
    }
    return thread->methods;
}
root_methods() click to toggle source

Returns the root methods (ie, methods that were not called by other methods) that were profiled while this thread was executing. Generally there is only one root method (multiple root methods can occur when Profile#pause is used). By starting with the root methods, you can descend down the profile call tree.

   # File lib/ruby-prof/thread.rb
 7 def root_methods
 8   self.methods.select do |method_info|
 9     method_info.root?
10   end
11 end
total_time() click to toggle source

Returns the total time this thread was executed.

   # File lib/ruby-prof/thread.rb
14 def total_time
15   self.root_methods.inject(0) do |sum, method_info|
16     method_info.callers.each do |call_info|
17       sum += call_info.total_time
18     end
19     sum
20   end
21 end
wait_time() click to toggle source

Returns the amount of time this thread waited while other thread executed.

   # File lib/ruby-prof/thread.rb
24 def wait_time
25   # wait_time, like self:time, is always method local
26   # thus we need to sum over all methods and call infos
27   self.methods.inject(0) do |sum, method_info|
28     method_info.callers.each do |call_info|
29       sum += call_info.wait_time
30     end
31     sum
32   end
33 end