Class: RubyProf::MethodInfo

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
ext/ruby_prof.c,
ext/ruby_prof.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::Result object.

Instance Method Summary collapse

Instance Method Details

#<=>(other) ⇒ Object

:nodoc:



861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
# File 'ext/ruby_prof.c', line 861

static VALUE
prof_method_cmp(VALUE self, VALUE other)
{
    /* For call graphs we want to sort methods by
       their total time, not self time. */
    prof_method_t *x = get_prof_method(self);
    prof_method_t *y = get_prof_method(other);

    if (x->called == 0 && y->called == 0)
      return INT2FIX(0);
    else if (x->called == 0)
      return INT2FIX(1);
    else if (y->called == 0)
      return INT2FIX(-1);
    else
      return rb_dbl_cmp(x->total_time, y->total_time);
}

#calledMethodInfo

For recursively called methods, returns the base method. Otherwise, returns self.

Returns:



798
799
800
801
802
803
804
805
806
807
808
809
810
# File 'ext/ruby_prof.c', line 798

static VALUE
prof_method_base(VALUE self)
{
    prof_method_t *method = get_prof_method(self);
    
    if (method == method->base)
      return self;
    else
      /* Target is a pointer to a method_info - so we have to be careful
         about the GC.  We will wrap the method_info but provide no
         free method so the underlying object is not freed twice! */
      return Data_Wrap_Struct(cMethodInfo, NULL, NULL, method->base);
}

#calledInteger

Returns the number of times this method was called.

Returns:

  • (Integer)


645
646
647
648
649
650
651
# File 'ext/ruby_prof.c', line 645

static VALUE
prof_method_called(VALUE self)
{
    prof_method_t *result = get_prof_method(self);

    return INT2NUM(result->called);
}

#childrenHash

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

Returns:

  • (Hash)


848
849
850
851
852
853
854
855
856
857
858
# File 'ext/ruby_prof.c', line 848

static VALUE
prof_method_children(VALUE self)
{
    /* Returns an array of call info objects for this
       method's callees (the methods this method called). */

    VALUE children = rb_ary_new();
    prof_method_t *result = get_prof_method(self);
    st_foreach(result->children, prof_method_collect_call_infos, children);
    return children;
}

#children_timeFloat

Returns the total amount of time spent in this method’s children.

Returns:

  • (Float)


704
705
706
707
708
709
710
# File 'ext/ruby_prof.c', line 704

static VALUE
prof_method_children_time(VALUE self)
{
    prof_method_t *result = get_prof_method(self);
    prof_measure_t children_time = result->total_time - result->self_time - result->wait_time;
    return rb_float_new(convert_measurement(children_time));
}

#full_nameString

Returns the full name of this method in the format Object#method.

Returns:

  • (String)


786
787
788
789
790
791
# File 'ext/ruby_prof.c', line 786

static VALUE
prof_full_name(VALUE self)
{
    prof_method_t *method = get_prof_method(self);
    return full_name(method->klass, method->mid, method->depth);
}

#method_classObject

Returns the Ruby klass that owns this method.



735
736
737
738
739
740
741
# File 'ext/ruby_prof.c', line 735

static VALUE
prof_method_klass(VALUE self)
{
    prof_method_t *result = get_prof_method(self);

    return result->klass;
}

#klass_nameString

Returns the name of this method’s class. Singleton classes will have the form <Object::Object>.

Returns:

  • (String)


761
762
763
764
765
766
# File 'ext/ruby_prof.c', line 761

static VALUE
prof_klass_name(VALUE self)
{
    prof_method_t *method = get_prof_method(self);
    return klass_name(method->klass);
}

#line_noInteger

returns the line number of the method

Returns:

  • (Integer)


694
695
696
697
698
# File 'ext/ruby_prof.c', line 694

static VALUE
prof_method_line(VALUE self)
{
    return rb_int_new(get_prof_method(self)->line);
}

#method_idObject

Returns the id of this method.



747
748
749
750
751
752
753
# File 'ext/ruby_prof.c', line 747

static VALUE
prof_method_id(VALUE self)
{
    prof_method_t *result = get_prof_method(self);

    return ID2SYM(result->mid);
}

#method_nameString

Returns the name of this method in the format Object#method. Singletons methods will be returned in the format <Object::Object>#method.

Returns:

  • (String)


774
775
776
777
778
779
# File 'ext/ruby_prof.c', line 774

static VALUE
prof_method_name(VALUE self)
{
    prof_method_t *method = get_prof_method(self);
    return method_name(method->mid, method->depth);
}

#childrenHash

Returns an array of call info objects of methods that this method was called by (ie, parents).

Returns:

  • (Hash)


830
831
832
833
834
835
836
837
838
839
840
# File 'ext/ruby_prof.c', line 830

static VALUE
prof_method_parents(VALUE self)
{
    /* Returns an array of call info objects for this
       method's callers (the methods this method called). */

    VALUE children = rb_ary_new();
    prof_method_t *result = get_prof_method(self);
    st_foreach(result->parents, prof_method_collect_call_infos, children);
    return children;
}

#self_timeFloat

Returns the total amount of time spent in this method.

Returns:

  • (Float)


670
671
672
673
674
675
676
# File 'ext/ruby_prof.c', line 670

static VALUE
prof_method_self_time(VALUE self)
{
    prof_method_t *result = get_prof_method(self);

    return rb_float_new(convert_measurement(result->self_time));
}

#source_fileString

return the source file of the method

Returns:

  • (String)


717
718
719
720
721
722
723
724
725
726
727
728
# File 'ext/ruby_prof.c', line 717

static VALUE prof_method_source_file(VALUE self)
{
    const char* sf = get_prof_method(self)->source_file;
    if(!sf)
    {
      return rb_str_new2("ruby_runtime");
    }
    else
    {
      return rb_str_new2(sf);
    }
}

#total_timeFloat

Returns the total amount of time spent in this method and its children.

Returns:

  • (Float)


658
659
660
661
662
663
664
# File 'ext/ruby_prof.c', line 658

static VALUE
prof_method_total_time(VALUE self)
{
    prof_method_t *result = get_prof_method(self);

    return rb_float_new(convert_measurement(result->total_time));
}

#wait_timeFloat

Returns the total amount of time this method waited for other threads.

Returns:

  • (Float)


682
683
684
685
686
687
688
# File 'ext/ruby_prof.c', line 682

static VALUE
prof_method_wait_time(VALUE self)
{
    prof_method_t *result = get_prof_method(self);

    return rb_float_new(convert_measurement(result->wait_time));
}