module RubyProf
The call info visitor class does a depth-first traversal across a list of method infos. 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.top_call_infos) 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
Based off ruby-prof 0.16.2
Public Class Methods
Measurements
# File lib/ruby-prof/compatibility.rb, line 6 def self.cpu_frequency Measure::CpuTime.frequency end
Returns threads ruby-prof should exclude from profiling
# File lib/ruby-prof/compatibility.rb, line 96 def self.exclude_threads @exclude_threads ||= Array.new end
Specifies what threads ruby-prof should exclude from profiling
# File lib/ruby-prof/compatibility.rb, line 105 def self.exclude_threads=(value) @exclude_threads = value end
Checks if the user specified the clock mode via the RUBY_PROF_MEASURE_MODE environment variable
# File lib/ruby-prof.rb, line 41 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" RubyProf.measure_mode = RubyProf::CPU_TIME when "allocations" RubyProf.measure_mode = RubyProf::ALLOCATIONS when "memory" RubyProf.measure_mode = RubyProf::MEMORY when "process", "process_time" RubyProf.measure_mode = RubyProf::PROCESS_TIME when "gc_time" RubyProf.measure_mode = RubyProf::GC_TIME when "gc_runs" RubyProf.measure_mode = RubyProf::GC_RUNS else # the default is defined in the measure_mode reader end end
# File lib/ruby-prof/compatibility.rb, line 10 def self.measure_allocations Measure::Allocations.measure end
# File lib/ruby-prof/compatibility.rb, line 14 def self.measure_cpu_time Measure::CpuTime.measure end
# File lib/ruby-prof/compatibility.rb, line 18 def self.measure_gc_runs Measure::GcRuns.measure end
# File lib/ruby-prof/compatibility.rb, line 22 def self.measure_gc_time Measure::GcTime.measure end
# File lib/ruby-prof/compatibility.rb, line 26 def self.measure_memory Measure::Memory.measure end
Returns what ruby-prof is measuring. Valid values include:
*RubyProf::WALL_TIME - Measure wall time using gettimeofday on Linx and GetLocalTime on Windows. This is default. *RubyProf::PROCESS_TIME - Measure process time. It is implemented using the clock functions in the C Runtime library. *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 51 def self.measure_mode measure_modes.first end
Specifies what ruby-prof should measure. Valid values include:
*RubyProf::WALL_TIME - Measure wall time using gettimeofday on Linx and GetLocalTime on Windows. This is default. *RubyProf::PROCESS_TIME - Measure process time. It is implemented using the clock functions in the C Runtime library. *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 67 def self.measure_mode=(value) self.measure_modes = [value] end
# File lib/ruby-prof/compatibility.rb, line 79 def self.measure_mode_string case measure_mode when WALL_TIME then "wall_time" when CPU_TIME then "cpu_time" when PROCESS_TIME then "process_time_time" when ALLOCATIONS then "allocations" when MEMORY then "memory" when GC_TIME then "gc_time" when GC_RUNS then "gc_runs" end end
# File lib/ruby-prof/compatibility.rb, line 71 def self.measure_modes @measure_modes ||= [RubyProf::WALL_TIME] end
# File lib/ruby-prof/compatibility.rb, line 75 def self.measure_modes=(value) @measure_modes = value end
# File lib/ruby-prof/compatibility.rb, line 30 def self.measure_process_time Measure::ProcessTime.measure end
# File lib/ruby-prof/compatibility.rb, line 34 def self.measure_wall_time Measure::WallTime.measure end
# File lib/ruby-prof/compatibility.rb, line 122 def self.pause ensure_running! disable_gc_stats_if_needed @profile.pause end
Profile
a block
# File lib/ruby-prof/compatibility.rb, line 151 def self.profile(options = {}, &block) ensure_not_running! gc_stat_was_enabled = enable_gc_stats_if_needed options = { measure_modes: [measure_mode], exclude_threads: exclude_threads }.merge!(options) result = Profile.profile(options, &block) disable_gc_stats_if_needed(gc_stat_was_enabled) result end
# File lib/ruby-prof/compatibility.rb, line 136 def self.resume ensure_running! enable_gc_stats_if_needed @profile.resume end
# File lib/ruby-prof/compatibility.rb, line 128 def self.running? if defined?(@profile) and @profile @profile.running? else false end end
# File lib/ruby-prof/compatibility.rb, line 115 def self.start ensure_not_running! @profile = Profile.new(measure_modes: measure_modes, exclude_threads: exclude_threads) enable_gc_stats_if_needed @profile.start end
Profiling
# File lib/ruby-prof/compatibility.rb, line 110 def self.start_script(script) start load script end
# File lib/ruby-prof/compatibility.rb, line 142 def self.stop ensure_running! result = @profile.stop disable_gc_stats_if_needed @profile = nil result end
Private Class Methods
# File lib/ruby-prof/compatibility.rb, line 177 def self.disable_gc_stats_if_needed(was_enabled=nil) was_enabled ||= defined?(@gc_stat_was_enabled) && @gc_stat_was_enabled GC.disable_stats if measure_mode_requires_gc_stats_enabled? && !was_enabled end
for GC.allocated_size to work GC statistics should be enabled
# File lib/ruby-prof/compatibility.rb, line 171 def self.enable_gc_stats_if_needed if measure_mode_requires_gc_stats_enabled? @gc_stat_was_enabled = GC.enable_stats end end
# File lib/ruby-prof/compatibility.rb, line 166 def self.ensure_not_running! raise(RuntimeError, "RubyProf is already running") if running? end
# File lib/ruby-prof/compatibility.rb, line 162 def self.ensure_running! raise(RuntimeError, "RubyProf.start was not yet called") unless running? end
# File lib/ruby-prof/compatibility.rb, line 182 def self.measure_mode_requires_gc_stats_enabled? GC.respond_to?(:enable_stats) && [RubyProf::MEMORY, RubyProf::GC_TIME, RubyProf::GC_RUNS].include?(measure_mode) end