Class: RubyProf::Thread
- Inherits:
-
Data
- Object
- Data
- RubyProf::Thread
- Defined in:
- ext/ruby_prof/rp_thread.c,
lib/ruby-prof/thread.rb,
ext/ruby_prof/rp_thread.c
Overview
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
Instance Method Summary collapse
-
#_dump_data ⇒ Object
:nodoc:.
-
#_load_data(data) ⇒ Object
:nodoc:.
-
#fiber_id ⇒ Numeric
Returns the fiber id of this thread.
-
#id ⇒ Numeric
Returns the thread id of this thread.
-
#methods ⇒ Array
Returns an array of methods that were called from this thread during program execution.
-
#root_methods ⇒ Object
Returns the root methods (ie, methods that were not called by other methods) that were profiled while this thread was executing.
-
#total_time ⇒ Object
Returns the total time this thread was executed.
-
#wait_time ⇒ Object
Returns the amount of time this thread waited while other thread executed.
Instance Method Details
#_dump_data ⇒ Object
:nodoc:
295 296 297 298 299 300 301 302 303 304 305 |
# File 'ext/ruby_prof/rp_thread.c', line 295
static VALUE
prof_thread_dump(VALUE self)
{
thread_data_t* thread_data = DATA_PTR(self);
VALUE result = rb_hash_new();
rb_hash_aset(result, ID2SYM(rb_intern("fiber_id")), thread_data->fiber_id);
rb_hash_aset(result, ID2SYM(rb_intern("methods")), prof_thread_methods(self));
return result;
}
|
#_load_data(data) ⇒ Object
:nodoc:
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 |
# File 'ext/ruby_prof/rp_thread.c', line 308
static VALUE
prof_thread_load(VALUE self, VALUE data)
{
thread_data_t* thread_data = DATA_PTR(self);
thread_data->object = self;
thread_data->fiber_id = rb_hash_aref(data, ID2SYM(rb_intern("fiber_id")));
VALUE methods = rb_hash_aref(data, ID2SYM(rb_intern("methods")));
for (int i = 0; i < rb_array_len(methods); i++)
{
VALUE method = rb_ary_entry(methods, i);
prof_method_t *method_data = DATA_PTR(method);
method_table_insert(thread_data->method_table, method_data->key, method_data);
}
return data;
}
|
#fiber_id ⇒ Numeric
Returns the fiber id of this thread.
270 271 272 273 274 275 |
# File 'ext/ruby_prof/rp_thread.c', line 270
static VALUE
prof_fiber_id(VALUE self)
{
thread_data_t* thread = prof_get_thread(self);
return thread->fiber_id;
}
|
#id ⇒ Numeric
Returns the thread id of this thread.
259 260 261 262 263 264 |
# File 'ext/ruby_prof/rp_thread.c', line 259
static VALUE
prof_thread_id(VALUE self)
{
thread_data_t* thread = prof_get_thread(self);
return thread->thread_id;
}
|
#methods ⇒ Array
Returns an array of methods that were called from this thread during program execution.
282 283 284 285 286 287 288 289 290 291 292 |
# File 'ext/ruby_prof/rp_thread.c', line 282
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 ⇒ Object
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.
7 8 9 10 11 |
# File 'lib/ruby-prof/thread.rb', line 7 def root_methods self.methods.select do |method_info| method_info.root? end end |
#total_time ⇒ Object
Returns the total time this thread was executed.
14 15 16 17 18 19 20 21 |
# File 'lib/ruby-prof/thread.rb', line 14 def total_time self.root_methods.inject(0) do |sum, method_info| method_info.callers.each do |call_info| sum += call_info.total_time end sum end end |
#wait_time ⇒ Object
Returns the amount of time this thread waited while other thread executed.
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/ruby-prof/thread.rb', line 24 def wait_time # wait_time, like self:time, is always method local # thus we need to sum over all methods and call infos self.methods.inject(0) do |sum, method_info| method_info.callers.each do |call_info| sum += call_info.wait_time end sum end end |