Class: RubyProf::MethodInfo
- Inherits:
-
Object
- Object
- RubyProf::MethodInfo
- Includes:
- Comparable
- Defined in:
- lib/ruby-prof/method_info.rb,
ext/ruby_prof/rp_method.c,
ext/ruby_prof/rp_method.c
Overview
The RubyProf::MethodInfo class stores profiling data for a method. One instance of the RubyProf::MethodInfo class is created per method called per thread. Thus, if a method is called in two different thread then there will be two RubyProf::MethodInfo objects created. RubyProf::MethodInfo objects can be accessed via the RubyProf::Profile object.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
:enddoc:.
-
#_dump_data ⇒ Object
:nodoc:.
-
#_load_data(data) ⇒ Object
:nodoc:.
-
#allocations ⇒ Array
Returns an array of allocation information.
-
#call_trees ⇒ CallTrees
Returns the CallTrees associated with this method.
-
#called ⇒ Object
The number of times this method was called.
-
#children_time ⇒ Object
The time this method’s children took to execute.
-
#full_name ⇒ Object
Returns the full name of a class.
-
#klass_flags ⇒ Integer
Returns the klass flags.
-
#klass_name ⇒ String
Returns the name of this method’s class.
-
#line_no ⇒ Integer
returns the line number of the method.
-
#called ⇒ Measurement
Returns the measurement associated with this method.
-
#method_name ⇒ String
Returns the name of this method in the format Object#method.
-
#recursive? ⇒ Boolean
Returns the true if this method is recursively invoked.
-
#self_time ⇒ Object
The time this method took to execute.
-
#source_file ⇒ String
return the source file of the method.
- #to_s ⇒ Object
-
#total_time ⇒ Object
The total time this method took - includes self time + wait time + child time.
-
#wait_time ⇒ Object
The time this method waited for other fibers/threads to execute.
Instance Method Details
#<=>(other) ⇒ Object
:enddoc:
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/ruby-prof/method_info.rb', line 56 def <=>(other) if other.nil? -1 elsif self.full_name == other.full_name 0 elsif self.total_time < other.total_time -1 elsif self.total_time > other.total_time 1 elsif self.call_trees.min_depth < other.call_trees.min_depth 1 elsif self.call_trees.min_depth > other.call_trees.min_depth -1 else self.full_name <=> other.full_name end end |
#_dump_data ⇒ Object
:nodoc:
414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 |
# File 'ext/ruby_prof/rp_method.c', line 414
static VALUE prof_method_dump(VALUE self)
{
prof_method_t* method_data = prof_get_method(self);
VALUE result = rb_hash_new();
rb_hash_aset(result, ID2SYM(rb_intern("klass_name")), prof_method_klass_name(self));
rb_hash_aset(result, ID2SYM(rb_intern("klass_flags")), INT2FIX(method_data->klass_flags));
rb_hash_aset(result, ID2SYM(rb_intern("method_name")), method_data->method_name);
rb_hash_aset(result, ID2SYM(rb_intern("key")), INT2FIX(method_data->key));
rb_hash_aset(result, ID2SYM(rb_intern("recursive")), prof_method_recursive(self));
rb_hash_aset(result, ID2SYM(rb_intern("source_file")), method_data->source_file);
rb_hash_aset(result, ID2SYM(rb_intern("source_line")), INT2FIX(method_data->source_line));
rb_hash_aset(result, ID2SYM(rb_intern("call_trees")), prof_call_trees_wrap(method_data->call_trees));
rb_hash_aset(result, ID2SYM(rb_intern("measurement")), prof_measurement_wrap(method_data->measurement));
rb_hash_aset(result, ID2SYM(rb_intern("allocations")), prof_method_allocations(self));
return result;
}
|
#_load_data(data) ⇒ Object
:nodoc:
436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 |
# File 'ext/ruby_prof/rp_method.c', line 436
static VALUE prof_method_load(VALUE self, VALUE data)
{
prof_method_t* method_data = prof_get_method(self);
method_data->object = self;
method_data->klass_name = rb_hash_aref(data, ID2SYM(rb_intern("klass_name")));
method_data->klass_flags = FIX2INT(rb_hash_aref(data, ID2SYM(rb_intern("klass_flags"))));
method_data->method_name = rb_hash_aref(data, ID2SYM(rb_intern("method_name")));
method_data->key = FIX2LONG(rb_hash_aref(data, ID2SYM(rb_intern("key"))));
method_data->recursive = rb_hash_aref(data, ID2SYM(rb_intern("recursive"))) == Qtrue ? true : false;
method_data->source_file = rb_hash_aref(data, ID2SYM(rb_intern("source_file")));
method_data->source_line = FIX2INT(rb_hash_aref(data, ID2SYM(rb_intern("source_line"))));
VALUE call_trees = rb_hash_aref(data, ID2SYM(rb_intern("call_trees")));
method_data->call_trees = prof_get_call_trees(call_trees);
VALUE measurement = rb_hash_aref(data, ID2SYM(rb_intern("measurement")));
method_data->measurement = prof_get_measurement(measurement);
VALUE allocations = rb_hash_aref(data, ID2SYM(rb_intern("allocations")));
for (int i = 0; i < rb_array_len(allocations); i++)
{
VALUE allocation = rb_ary_entry(allocations, i);
prof_allocation_t* allocation_data = prof_allocation_get(allocation);
rb_st_insert(method_data->allocations_table, allocation_data->key, (st_data_t)allocation_data);
}
return data;
}
|
#allocations ⇒ Array
Returns an array of allocation information.
316 317 318 319 320 321 322 |
# File 'ext/ruby_prof/rp_method.c', line 316
static VALUE prof_method_allocations(VALUE self)
{
prof_method_t* method = prof_get_method(self);
VALUE result = rb_ary_new();
rb_st_foreach(method->allocations_table, prof_method_collect_allocations, result);
return result;
}
|
#call_trees ⇒ CallTrees
Returns the CallTrees associated with this method.
407 408 409 410 411 |
# File 'ext/ruby_prof/rp_method.c', line 407
static VALUE prof_method_call_trees(VALUE self)
{
prof_method_t* method = prof_get_method(self);
return prof_call_trees_wrap(method->call_trees);
}
|
#called ⇒ Object
The number of times this method was called
31 32 33 |
# File 'lib/ruby-prof/method_info.rb', line 31 def called self.measurement.called end |
#children_time ⇒ Object
The time this method’s children took to execute
51 52 53 |
# File 'lib/ruby-prof/method_info.rb', line 51 def children_time self.total_time - self.self_time - self.wait_time end |
#full_name ⇒ Object
Returns the full name of a class. The interpretation of method names is:
-
MyObject#test - An method defined in a class
-
<Class:MyObject>#test - A method defined in a singleton class.
-
<Module:MyObject>#test - A method defined in a singleton module.
-
<Object:MyObject>#test - A method defined in a singleton object.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/ruby-prof/method_info.rb', line 15 def full_name decorated_class_name = case self.klass_flags when 0x2 "<Class::#{klass_name}>" when 0x4 "<Module::#{klass_name}>" when 0x8 "<Object::#{klass_name}>" else klass_name end "#{decorated_class_name}##{method_name}" end |
#klass_flags ⇒ Integer
Returns the klass flags
375 376 377 378 379 |
# File 'ext/ruby_prof/rp_method.c', line 375
static VALUE prof_method_klass_flags(VALUE self)
{
prof_method_t* method = prof_get_method(self);
return INT2FIX(method->klass_flags);
}
|
#klass_name ⇒ String
Returns the name of this method’s class. Singleton classes will have the form <Object::Object>.
361 362 363 364 365 366 367 368 |
# File 'ext/ruby_prof/rp_method.c', line 361
static VALUE prof_method_klass_name(VALUE self)
{
prof_method_t* method = prof_get_method(self);
if (method->klass_name == Qnil)
method->klass_name = resolve_klass_name(method->klass, &method->klass_flags);
return method->klass_name;
}
|
#line_no ⇒ Integer
returns the line number of the method
349 350 351 352 353 |
# File 'ext/ruby_prof/rp_method.c', line 349
static VALUE prof_method_line(VALUE self)
{
prof_method_t* method = prof_get_method(self);
return INT2FIX(method->source_line);
}
|
#called ⇒ Measurement
Returns the measurement associated with this method.
328 329 330 331 332 |
# File 'ext/ruby_prof/rp_method.c', line 328
static VALUE prof_method_measurement(VALUE self)
{
prof_method_t* method = prof_get_method(self);
return prof_measurement_wrap(method->measurement);
}
|
#method_name ⇒ String
Returns the name of this method in the format Object#method. Singletons methods will be returned in the format <Object::Object>#method.
387 388 389 390 391 |
# File 'ext/ruby_prof/rp_method.c', line 387
static VALUE prof_method_name(VALUE self)
{
prof_method_t* method = prof_get_method(self);
return method->method_name;
}
|
#recursive? ⇒ Boolean
Returns the true if this method is recursively invoked
397 398 399 400 401 |
# File 'ext/ruby_prof/rp_method.c', line 397
static VALUE prof_method_recursive(VALUE self)
{
prof_method_t* method = prof_get_method(self);
return method->recursive ? Qtrue : Qfalse;
}
|
#self_time ⇒ Object
The time this method took to execute
41 42 43 |
# File 'lib/ruby-prof/method_info.rb', line 41 def self_time self.measurement.self_time end |
#source_file ⇒ String
return the source file of the method
339 340 341 342 343 |
# File 'ext/ruby_prof/rp_method.c', line 339
static VALUE prof_method_source_file(VALUE self)
{
prof_method_t* method = prof_get_method(self);
return method->source_file;
}
|
#to_s ⇒ Object
74 75 76 |
# File 'lib/ruby-prof/method_info.rb', line 74 def to_s "#{self.full_name} (c: #{self.called}, tt: #{self.total_time}, st: #{self.self_time}, wt: #{wait_time}, ct: #{self.children_time})" end |
#total_time ⇒ Object
The total time this method took - includes self time + wait time + child time
36 37 38 |
# File 'lib/ruby-prof/method_info.rb', line 36 def total_time self.measurement.total_time end |
#wait_time ⇒ Object
The time this method waited for other fibers/threads to execute
46 47 48 |
# File 'lib/ruby-prof/method_info.rb', line 46 def wait_time self.measurement.wait_time end |