Class: RubyProf::CallTree

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

Overview

The CallTree class is used to track the relationships between methods. It is a helper class used by RubyProf::MethodInfo to keep track of which methods called a given method and which methods a given method called. Each CallTree has a parent and target method. You cannot create a CallTree object directly, they are generated while running a profile.

Direct Known Subclasses

AggregateCallTree

Instance Method Summary collapse

Instance Method Details

#<=>(other) ⇒ Object

Compares two CallTree instances. The comparison is based on the CallTree#parent, CallTree#target, and total time.



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/ruby-prof/call_tree.rb', line 36

def <=>(other)
  if self.target == other.target && self.parent == other.parent
    0
  elsif self.total_time < other.total_time
    -1
  elsif self.total_time > other.total_time
    1
  else
    self.target.full_name <=> other.target.full_name
  end
end

#_dump_dataObject

:nodoc:



300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
# File 'ext/ruby_prof/rp_call_tree.c', line 300

static VALUE prof_call_tree_dump(VALUE self)
{
    prof_call_tree_t* call_tree_data = prof_get_call_tree(self);
    VALUE result = rb_hash_new();

    rb_hash_aset(result, ID2SYM(rb_intern("measurement")), prof_measurement_wrap(call_tree_data->measurement));

    rb_hash_aset(result, ID2SYM(rb_intern("source_file")), call_tree_data->source_file);
    rb_hash_aset(result, ID2SYM(rb_intern("source_line")), INT2FIX(call_tree_data->source_line));

    rb_hash_aset(result, ID2SYM(rb_intern("parent")), prof_call_tree_parent(self));
    rb_hash_aset(result, ID2SYM(rb_intern("children")), prof_call_tree_children(self));
    rb_hash_aset(result, ID2SYM(rb_intern("target")), prof_call_tree_target(self));

    return result;
}

#_load_data(data) ⇒ Object

:nodoc:



318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
# File 'ext/ruby_prof/rp_call_tree.c', line 318

static VALUE prof_call_tree_load(VALUE self, VALUE data)
{
    VALUE target = Qnil;
    VALUE parent = Qnil;
    prof_call_tree_t* call_tree = prof_get_call_tree(self);
    call_tree->object = self;

    VALUE measurement = rb_hash_aref(data, ID2SYM(rb_intern("measurement")));
    call_tree->measurement = prof_get_measurement(measurement);

    call_tree->source_file = rb_hash_aref(data, ID2SYM(rb_intern("source_file")));
    call_tree->source_line = FIX2INT(rb_hash_aref(data, ID2SYM(rb_intern("source_line"))));

    parent = rb_hash_aref(data, ID2SYM(rb_intern("parent")));
    if (parent != Qnil)
        call_tree->parent = prof_get_call_tree(parent);

    VALUE callees = rb_hash_aref(data, ID2SYM(rb_intern("children")));
    for (int i = 0; i < rb_array_len(callees); i++)
    {
        VALUE call_tree_object = rb_ary_entry(callees, i);
        prof_call_tree_t* call_tree_data = prof_get_call_tree(call_tree_object);

        st_data_t key = call_tree_data->method ? call_tree_data->method->key : method_key(Qnil, 0);
        call_tree_table_insert(call_tree->children, key, call_tree_data);
    }

    target = rb_hash_aref(data, ID2SYM(rb_intern("target")));
    call_tree->method = prof_get_method(target);

    return data;
}

#calledObject

The number of times the parent method called the target method



10
11
12
# File 'lib/ruby-prof/call_tree.rb', line 10

def called
  self.measurement.called
end

#calleesArray

Returns an array of call info objects that this method called (ie, children).

Returns:

  • (Array)


239
240
241
242
243
244
245
# File 'ext/ruby_prof/rp_call_tree.c', line 239

static VALUE prof_call_tree_children(VALUE self)
{
    prof_call_tree_t* call_tree = prof_get_call_tree(self);
    VALUE result = rb_ary_new();
    rb_st_foreach(call_tree->children, prof_call_tree_collect_children, result);
    return result;
}

#children_timeObject

The time spent in child methods resulting from the parent method calling the target method



30
31
32
# File 'lib/ruby-prof/call_tree.rb', line 30

def children_time
  self.total_time - self.self_time - self.wait_time
end

#depthInteger

returns the depth of this call info in the call graph

Returns:

  • (Integer)


271
272
273
274
275
276
# File 'ext/ruby_prof/rp_call_tree.c', line 271

static VALUE prof_call_tree_depth(VALUE self)
{
    prof_call_tree_t* call_tree_data = prof_get_call_tree(self);
    uint32_t depth = prof_call_figure_depth(call_tree_data);
    return rb_int_new(depth);
}

#inspectObject



53
54
55
# File 'lib/ruby-prof/call_tree.rb', line 53

def inspect
  self.to_s
end

#line_noInteger

returns the line number of the method

Returns:

  • (Integer)


293
294
295
296
297
# File 'ext/ruby_prof/rp_call_tree.c', line 293

static VALUE prof_call_tree_line(VALUE self)
{
    prof_call_tree_t* result = prof_get_call_tree(self);
    return INT2FIX(result->source_line);
}

#calledMeasurement

Returns the measurement associated with this call_tree.

Returns:



261
262
263
264
265
# File 'ext/ruby_prof/rp_call_tree.c', line 261

static VALUE prof_call_tree_measurement(VALUE self)
{
    prof_call_tree_t* call_tree = prof_get_call_tree(self);
    return prof_measurement_wrap(call_tree->measurement);
}

#parentObject

Returns the CallTree parent call_tree object (the method that called this method).



226
227
228
229
230
231
232
233
# File 'ext/ruby_prof/rp_call_tree.c', line 226

static VALUE prof_call_tree_parent(VALUE self)
{
    prof_call_tree_t* call_tree = prof_get_call_tree(self);
    if (call_tree->parent)
        return prof_call_tree_wrap(call_tree->parent);
    else
        return Qnil;
}

#self_timeObject

The self time (of the parent) resulting from the parent method calling the target method



20
21
22
# File 'lib/ruby-prof/call_tree.rb', line 20

def self_time
  self.measurement.self_time
end

#source_fileString

return the source file of the method

Returns:

  • (String)


283
284
285
286
287
# File 'ext/ruby_prof/rp_call_tree.c', line 283

static VALUE prof_call_tree_source_file(VALUE self)
{
    prof_call_tree_t* result = prof_get_call_tree(self);
    return result->source_file;
}

#calledMethodInfo

Returns the target method.

Returns:



251
252
253
254
255
# File 'ext/ruby_prof/rp_call_tree.c', line 251

static VALUE prof_call_tree_target(VALUE self)
{
    prof_call_tree_t* call_tree = prof_get_call_tree(self);
    return prof_method_wrap(call_tree->method);
}

#to_sObject

:nodoc:



49
50
51
# File 'lib/ruby-prof/call_tree.rb', line 49

def to_s
  "<#{self.class.name} - #{self.target.full_name}>"
end

#total_timeObject

The total time resulting from the parent method calling the target method



15
16
17
# File 'lib/ruby-prof/call_tree.rb', line 15

def total_time
  self.measurement.total_time
end

#wait_timeObject

The wait time (of the parent) resulting from the parent method calling the target method



25
26
27
# File 'lib/ruby-prof/call_tree.rb', line 25

def wait_time
  self.measurement.wait_time
end