Module RubyProf
In: lib/ruby-prof.rb
lib/ruby-prof/abstract_printer.rb
lib/ruby-prof/call_tree_printer.rb
lib/ruby-prof/flat_printer.rb
lib/ruby-prof/graph_html_printer.rb
lib/ruby-prof/graph_printer.rb
lib/ruby-prof/task.rb
ext/ruby_prof.c
   call-seq:
   profile {block} -> RubyProf::Result

Profiles the specified block and returns a RubyProf::Result object.

Methods

Classes and Modules

Class RubyProf::AbstractPrinter
Class RubyProf::CallInfo
Class RubyProf::CallTreePrinter
Class RubyProf::FlatPrinter
Class RubyProf::GraphHtmlPrinter
Class RubyProf::GraphPrinter
Class RubyProf::MethodInfo
Class RubyProf::ProfileTask
Class RubyProf::Result

Constants

VERSION = rb_str_new2(PROF_VERSION)
PROCESS_TIME = INT2NUM(MEASURE_PROCESS_TIME)
WALL_TIME = INT2NUM(MEASURE_WALL_TIME)
CPU_TIME = INT2NUM(MEASURE_CPU_TIME)
ALLOCATED_OBJECTS = INT2NUM(MEASURE_ALLOCATIONS)

Public Class methods

See if the user specified the clock mode via the RUBY_PROF_MEASURE_MODE environment variable

[Source]

    # File lib/ruby-prof.rb, line 11
11:   def self.figure_measure_mode
12:     case ENV["RUBY_PROF_MEASURE_MODE"]
13:     when "wall" || "wall_time"
14:       RubyProf.measure_mode = RubyProf::WALL_TIME
15:     when "cpu" || "cpu_time"
16:       if ENV.key?("RUBY_PROF_CPU_FREQUENCY")
17:         RubyProf.cpu_frequency = ENV["RUBY_PROF_CPU_FREQUENCY"].to_f
18:       else
19:         begin
20:           open("/proc/cpuinfo") do |f|
21:             f.each_line do |line|
22:               s = line.slice(/cpu MHz\s*:\s*(.*)/, 1)
23:               if s
24:                 RubyProf.cpu_frequency = s.to_f * 1000000
25:                 break
26:               end
27:             end
28:           end
29:         rescue Errno::ENOENT
30:         end
31:       end
32:       RubyProf.measure_mode = RubyProf::CPU_TIME
33:     when "allocations"
34:       RubyProf.measure_mode = RubyProf::ALLOCATIONS
35:     else
36:       RubyProf.measure_mode = RubyProf::PROCESS_TIME
37:     end
38:   end

Returns what ruby-prof is measuring. Valid values include:

 RubyProf::PROCESS_TIME - Measure process time.  This is default.  It is implemented using the clock functions in the C Runtime library.
 RubyProf::WALL_TIME - Measure wall time using gettimeofday on Linx and GetLocalTime on Windows
 RubyProf::CPU_TIME - Measure time using the CPU clock counter.  This mode is only supported on Pentium or PowerPC platforms.
 RubyProf::ALLOCATIONS - Measure object allocations.  This requires a patched Ruby interpreter.

[Source]

/* call-seq:
   measure_mode -> measure_mode
   
   Returns what ruby-prof is measuring.  Valid values include:
   
   *RubyProf::PROCESS_TIME - Measure process time.  This is default.  It is implemented using the clock functions in the C Runtime library.
   *RubyProf::WALL_TIME - Measure wall time using gettimeofday on Linx and GetLocalTime on Windows
   *RubyProf::CPU_TIME - Measure time using the CPU clock counter.  This mode is only supported on Pentium or PowerPC platforms. 
   *RubyProf::ALLOCATIONS - Measure object allocations.  This requires a patched Ruby interpreter.*/
static VALUE
prof_get_measure_mode(VALUE self)
{
    return INT2NUM(measure_mode);
}

Specifies what ruby-prof should measure. Valid values include:

 RubyProf::PROCESS_TIME - Measure process time.  This is default.  It is implemented using the clock functions in the C Runtime library.
 RubyProf::WALL_TIME - Measure wall time using gettimeofday on Linx and GetLocalTime on Windows
 RubyProf::CPU_TIME - Measure time using the CPU clock counter.  This mode is only supported on Pentium or PowerPC platforms.
 RubyProf::ALLOCATIONS - Measure object allocations.  This requires a patched Ruby interpreter.

[Source]

/* call-seq:
   measure_mode=value -> void
   
   Specifies what ruby-prof should measure.  Valid values include:
   
   *RubyProf::PROCESS_TIME - Measure process time.  This is default.  It is implemented using the clock functions in the C Runtime library.
   *RubyProf::WALL_TIME - Measure wall time using gettimeofday on Linx and GetLocalTime on Windows
   *RubyProf::CPU_TIME - Measure time using the CPU clock counter.  This mode is only supported on Pentium or PowerPC platforms. 
   *RubyProf::ALLOCATIONS - Measure object allocations.  This requires a patched Ruby interpreter.*/
static VALUE
prof_set_measure_mode(VALUE self, VALUE val)
{
    long mode = NUM2LONG(val);

    if (threads_tbl)
    {
      rb_raise(rb_eRuntimeError, "can't set measure_mode while profiling");
    }

    switch (mode) {
      case MEASURE_PROCESS_TIME:
        get_measurement = measure_process_time;
        convert_measurement = convert_process_time;
        break;
        
      case MEASURE_WALL_TIME:
        get_measurement = measure_wall_time;
        convert_measurement = convert_wall_time;
        break;
        
      #if defined(MEASURE_CPU_TIME)
      case MEASURE_CPU_TIME:
        if (cpu_frequency == 0)
            cpu_frequency = measure_cpu_time();
        get_measurement = measure_cpu_time;
        convert_measurement = convert_cpu_time;
        break;
      #endif
              
      #if defined(MEASURE_ALLOCATIONS)
      case MEASURE_ALLOCATIONS:
        get_measurement = measure_allocations;
        convert_measurement = convert_allocations;
        break;
      #endif
        
      default:
        rb_raise(rb_eArgError, "invalid mode: %d", mode);
        break;
    }
    
    measure_mode = mode;
    return val;
}

Profiles the specified block and returns a RubyProf::Result object.

[Source]

/* call-seq:
   profile {block} -> RubyProf::Result

Profiles the specified block and returns a RubyProf::Result object. */
static VALUE
prof_profile(VALUE self)
{
    if (!rb_block_given_p())
    {
        rb_raise(rb_eArgError, "A block must be provided to the profile method.");
    }

    prof_start(self);
    rb_yield(Qnil);
    return prof_stop(self);
}

Returns whether a profile is currently running.

[Source]

/* call-seq:
   running? -> boolean
   
   Returns whether a profile is currently running.*/
static VALUE
prof_running(VALUE self)
{
    if (threads_tbl != NULL)
        return Qtrue;
    else
        return Qfalse;
}

Starts recording profile data.

[Source]

/* call-seq:
   start -> void
   
   Starts recording profile data.*/
static VALUE
prof_start(VALUE self)
{
    if (threads_tbl != NULL)
    {
        rb_raise(rb_eRuntimeError, "RubyProf.start was already called");
    }

    /* Setup globals */
    last_thread_data = NULL;
    threads_tbl = threads_table_create();
    
    rb_add_event_hook(prof_event_hook,
          RUBY_EVENT_CALL | RUBY_EVENT_RETURN |
          RUBY_EVENT_C_CALL | RUBY_EVENT_C_RETURN 
          | RUBY_EVENT_LINE);

    return Qnil;
}

Stops collecting profile data and returns a RubyProf::Result object.

[Source]

/* call-seq:
   stop -> RubyProf::Result

   Stops collecting profile data and returns a RubyProf::Result object. */
static VALUE
prof_stop(VALUE self)
{
    VALUE result = Qnil;

    if (threads_tbl == NULL)
    {
        rb_raise(rb_eRuntimeError, "RubyProf is not running.");
    }

    /* Now unregister from event   */
    rb_remove_event_hook(prof_event_hook);

    /* Create the result */
    result = prof_result_new();

    /* Unset the last_thread_data (very important!) 
       and the threads table */
    last_thread_data = NULL;
    threads_table_free(threads_tbl);
    threads_tbl = NULL;

    return result;
}

[Validate]