module RubyProf

The call info visitor class does a depth-first traversal across a thread's call stack. At each call_info node, the visitor executes the block provided in the visit method. The block is passed two parameters, the event and the call_info instance. Event will be either :enter or :exit.

visitor = RubyProf::CallInfoVisitor.new(result.threads.first)

method_names = Array.new

visitor.visit do |call_info, event|
  method_names << call_info.target.full_name if event == :enter
end

puts method_names

These methods are here for backwards compatability with previous RubyProf releases

Constants

VERSION

Public Class Methods

cpu_frequency() click to toggle source

Measurements

# File lib/ruby-prof/compatibility.rb, line 5
def self.cpu_frequency
  Measure::CpuTime.frequency
end
cpu_frequency=(value) click to toggle source
# File lib/ruby-prof/compatibility.rb, line 9
def self.cpu_frequency=(value)
  Measure::CpuTime.frequency = value
end
exclude_threads → exclude_threads click to toggle source

Returns threads ruby-prof should exclude from profiling

# File lib/ruby-prof/compatibility.rb, line 79
def self.exclude_threads
  @exclude_threads ||= Array.new
end
exclude_threads= → void click to toggle source

Specifies what threads ruby-prof should exclude from profiling

# File lib/ruby-prof/compatibility.rb, line 88
def self.exclude_threads=(value)
  @exclude_threads = value
end
figure_measure_mode() click to toggle source

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

# File lib/ruby-prof.rb, line 34
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(/cpu 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() click to toggle source
# File lib/ruby-prof/compatibility.rb, line 13
def self.measure_allocations
  Measure::Allocations.measure
end
measure_cpu_time() click to toggle source
# File lib/ruby-prof/compatibility.rb, line 17
def self.measure_cpu_time
  Measure::CpuTime.measure
end
measure_gc_runs() click to toggle source
# File lib/ruby-prof/compatibility.rb, line 21
def self.measure_gc_runs
  Measure::GcRuns.measure
end
measure_gc_time() click to toggle source
# File lib/ruby-prof/compatibility.rb, line 25
def self.measure_gc_time
  Measure::GcTime.measure
end
measure_memory() click to toggle source
# File lib/ruby-prof/compatibility.rb, line 29
def self.measure_memory
  Measure::Memory.measure
end
measure_mode → measure_mode click to toggle source

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.*/

# File lib/ruby-prof/compatibility.rb, line 54
def self.measure_mode
  @measure_mode ||= RubyProf::WALL_TIME
end
measure_mode=value → void click to toggle source

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.*/

# File lib/ruby-prof/compatibility.rb, line 70
def self.measure_mode=(value)
  @measure_mode = value
end
measure_process_time() click to toggle source
# File lib/ruby-prof/compatibility.rb, line 33
def self.measure_process_time
  Measure::ProcessTime.measure
end
measure_wall_time() click to toggle source
# File lib/ruby-prof/compatibility.rb, line 37
def self.measure_wall_time
  Measure::WallTime.measure
end
pause() click to toggle source
# File lib/ruby-prof/compatibility.rb, line 105
def self.pause
  ensure_running!
  disable_gc_stats_if_needed
  @profile.pause
end
profile(&block) click to toggle source

Profile a block

# File lib/ruby-prof/compatibility.rb, line 134
def self.profile(&block)
  ensure_not_running!
  gc_stat_was_enabled = enable_gc_stats_if_needed
  res = Profile.profile(self.measure_mode, self.exclude_threads, &block)
  disable_gc_stats_if_needed(gc_stat_was_enabled)
  res
end
resume() click to toggle source
# File lib/ruby-prof/compatibility.rb, line 119
def self.resume
  ensure_running!
  enable_gc_stats_if_needed
  @profile.resume
end
running?() click to toggle source
# File lib/ruby-prof/compatibility.rb, line 111
def self.running?
  if defined?(@profile) and @profile
    @profile.running?
  else
    false
  end
end
start() click to toggle source
# File lib/ruby-prof/compatibility.rb, line 98
def self.start
  ensure_not_running!
  @profile = Profile.new(self.measure_mode, self.exclude_threads)
  enable_gc_stats_if_needed
  @profile.start
end
start_script(script) click to toggle source

Profiling

# File lib/ruby-prof/compatibility.rb, line 93
def self.start_script(script)
  start
  load script
end
stop() click to toggle source
# File lib/ruby-prof/compatibility.rb, line 125
def self.stop
  ensure_running!
  result = @profile.stop
  disable_gc_stats_if_needed
  @profile = nil
  result
end