module RubyProf

  1. ext/ruby_prof/ruby_prof.c
  2. lib/ruby-prof/abstract_printer.rb
  3. lib/ruby-prof/aggregate_call_info.rb
  4. lib/ruby-prof/call_info.rb
  5. lib/ruby-prof/call_stack_printer.rb
  6. lib/ruby-prof/call_tree_printer.rb
  7. lib/ruby-prof/compatibility.rb
  8. lib/ruby-prof/dot_printer.rb
  9. lib/ruby-prof/flat_printer.rb
  10. lib/ruby-prof/flat_printer_with_line_numbers.rb
  11. lib/ruby-prof/graph_html_printer.rb
  12. lib/ruby-prof/graph_printer.rb
  13. lib/ruby-prof/method_info.rb
  14. lib/ruby-prof/multi_printer.rb
  15. lib/ruby-prof/profile.rb
  16. lib/ruby-prof/task.rb
  17. lib/ruby-prof/test.rb
  18. lib/ruby-prof.rb
  19. test/test_helper.rb
  20. show all
Parent: test_helper.rb

These methods are here for backwards compatability with previous RubyProf releases

Some classes used in measurement tests

Constants

PARENT = Object  
VERSION = rb_str_new2(RUBY_PROF_VERSION)  

Public Class methods

camelcase (phrase)
[show source]
# File lib/ruby-prof.rb, line 12
def self.camelcase(phrase)
  ('_' + phrase).gsub(%r_([a-z])/){|b| b[1..1].upcase}
end
cpu_frequency ()

Measurements

[show source]
# File lib/ruby-prof/compatibility.rb, line 5
def self.cpu_frequency
  Measure::CpuTime.frequency
end
cpu_frequency= (value)
[show source]
# File lib/ruby-prof/compatibility.rb, line 9
def self.cpu_frequency=(value)
  Measure::CpuTime.frequency = value
end
exclude_threads= -> void

Specifies what threads ruby-prof should exclude from profiling

[show source]
# File lib/ruby-prof/compatibility.rb, line 79
def self.exclude_threads
  @exclude_threads ||= Array.new
end
exclude_threads= (value)
[show source]
# File lib/ruby-prof/compatibility.rb, line 83
def self.exclude_threads=(value)
  @exclude_threads = value
end
figure_measure_mode ()

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

[show source]
# File lib/ruby-prof.rb, line 36
def self.figure_measure_mode
  case ENV["RUBY_PROF_MEASURE_MODE"]
  when "wall" || "wall_time"
    RubyProf.measure_mode = RubyProf::WALL_TIME
  when "cpu" || "cpu_time"
    if ENV.key?("RUBY_PROF_CPU_FREQUENCY")
      RubyProf.cpu_frequency = ENV["RUBY_PROF_CPU_FREQUENCY"].to_f
    else
      begin
        open("/proc/cpuinfo") do |f|
          f.each_line do |line|
            s = line.slice(%rcpu MHz\s*:\s*(.*)/, 1)
            if s
              RubyProf.cpu_frequency = s.to_f * 1000000
              break
            end
          end
        end
      rescue Errno::ENOENT
      end
    end
    RubyProf.measure_mode = RubyProf::CPU_TIME
  when "allocations"
    RubyProf.measure_mode = RubyProf::ALLOCATIONS
  when "memory"
    RubyProf.measure_mode = RubyProf::MEMORY
  else
    # the default...
    RubyProf.measure_mode = RubyProf::PROCESS_TIME
  end
end
measure_allocations ()
[show source]
# File lib/ruby-prof/compatibility.rb, line 13
def self.measure_allocations
  Measure::Allocations.measure
end
measure_cpu_time ()
[show source]
# File lib/ruby-prof/compatibility.rb, line 17
def self.measure_cpu_time
  Measure::CpuTime.measure
end
measure_gc_runs ()
[show source]
# File lib/ruby-prof/compatibility.rb, line 21
def self.measure_gc_runs
  Measure::GcRuns.measure
end
measure_gc_time ()
[show source]
# File lib/ruby-prof/compatibility.rb, line 25
def self.measure_gc_time
  Measure::GcTime.measure
end
measure_memory ()
[show source]
# File lib/ruby-prof/compatibility.rb, line 29
def self.measure_memory
  Measure::Memory.measure
end
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. *RubyProf::MEMORY - Measure memory size. This requires a patched Ruby interpreter. *RubyProf::GC_RUNS - Measure number of garbage collections. This requires a patched Ruby interpreter. *RubyProf::GC_TIME - Measure time spent doing garbage collection. This requires a patched Ruby interpreter.*/

[show source]
# File lib/ruby-prof/compatibility.rb, line 54
def self.measure_mode
  @measure_mode ||= RubyProf::WALL_TIME
end
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. *RubyProf::MEMORY - Measure memory size. This requires a patched Ruby interpreter. *RubyProf::GC_RUNS - Measure number of garbage collections. This requires a patched Ruby interpreter. *RubyProf::GC_TIME - Measure time spent doing garbage collection. This requires a patched Ruby interpreter.*/

[show source]
# File lib/ruby-prof/compatibility.rb, line 70
def self.measure_mode=(value)
  @measure_mode = value
end
measure_process_time ()
[show source]
# File lib/ruby-prof/compatibility.rb, line 33
def self.measure_process_time
  Measure::ProcessTime.measure
end
measure_wall_time ()
[show source]
# File lib/ruby-prof/compatibility.rb, line 37
def self.measure_wall_time
  Measure::WallTime.measure
end
pause ()
[show source]
# File lib/ruby-prof/compatibility.rb, line 96
def self.pause
  unless @profile
    raise(RuntimeError, "RubyProf.start was not yet called");
  end
  @profile.pause
end
profile (&block)
[show source]
# File lib/ruby-prof/compatibility.rb, line 127
def self.profile(&block)
  if @profile
    raise(RuntimeError, "RubyProf is already running");
  end
  Profile.profile(self.measure_mode, self.exclude_threads, &block)
end
resume ()
[show source]
# File lib/ruby-prof/compatibility.rb, line 111
def self.resume
  unless @profile
    raise(RuntimeError, "RubyProf.start was not yet called");
  end
  @profile.resume
end
running? ()
[show source]
# File lib/ruby-prof/compatibility.rb, line 103
def self.running?
  if @profile
    @profile.running?
  else
    false
  end
end
start ()

Profiling

[show source]
# File lib/ruby-prof/compatibility.rb, line 88
def self.start
  if @profile
    raise(RuntimeError, "RubyProf is already running");
  end
  @profile = Profile.new(self.measure_mode, self.exclude_threads)
  @profile.start
end
stop ()
[show source]
# File lib/ruby-prof/compatibility.rb, line 118
def self.stop
  unless @profile
    raise(RuntimeError, "RubyProf.start was not yet called");
  end
  result = @profile.stop
  @profile = nil
  result
end