Module: RubyProf
- Defined in:
- lib/ruby-prof/compatibility.rb,
lib/ruby-prof.rb,
lib/ruby-prof/task.rb,
lib/ruby-prof/test.rb,
lib/ruby-prof/thread.rb,
lib/ruby-prof/profile.rb,
lib/ruby-prof/call_info.rb,
lib/ruby-prof/method_info.rb,
lib/ruby-prof/call_info_visitor.rb,
lib/ruby-prof/aggregate_call_info.rb,
lib/ruby-prof/printers/dot_printer.rb,
lib/ruby-prof/printers/flat_printer.rb,
lib/ruby-prof/printers/graph_printer.rb,
lib/ruby-prof/printers/multi_printer.rb,
lib/ruby-prof/printers/abstract_printer.rb,
lib/ruby-prof/printers/call_info_printer.rb,
lib/ruby-prof/printers/call_tree_printer.rb,
lib/ruby-prof/printers/call_stack_printer.rb,
lib/ruby-prof/printers/graph_html_printer.rb,
lib/ruby-prof/printers/flat_printer_with_line_numbers.rb,
ext/ruby_prof/ruby_prof.c
Overview
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
Defined Under Namespace
Modules: Measure, Test Classes: AbstractPrinter, AggregateCallInfo, CallInfo, CallInfoPrinter, CallInfoVisitor, CallStackPrinter, CallTreePrinter, DotPrinter, FlatPrinter, FlatPrinterWithLineNumbers, GraphHtmlPrinter, GraphPrinter, MethodInfo, MultiPrinter, Profile, ProfileTask, Thread
Constant Summary collapse
- VERSION =
rb_str_new2(RUBY_PROF_VERSION)
- MEMORY =
INT2NUM(MEASURE_MEMORY)
- MEMORY_ENABLED =
MEASURE_MEMORY_ENABLED
- GC_RUNS =
INT2NUM(MEASURE_GC_RUNS)
- GC_RUNS_ENABLED =
MEASURE_GC_RUNS_ENABLED
- GC_TIME =
INT2NUM(MEASURE_GC_TIME)
- GC_TIME_ENABLED =
MEASURE_GC_TIME_ENABLED
- CPU_TIME =
INT2NUM(MEASURE_CPU_TIME)
- CPU_TIME_ENABLED =
Qtrue
- WALL_TIME =
INT2NUM(MEASURE_WALL_TIME)
- WALL_TIME_ENABLED =
Qtrue
- ALLOCATIONS =
INT2NUM(MEASURE_ALLOCATIONS)
- ALLOCATIONS_ENABLED =
MEASURE_ALLOCATIONS_ENABLED
- CLOCKS_PER_SEC =
INT2NUM(CLOCKS_PER_SEC)
- PROCESS_TIME =
INT2NUM(MEASURE_PROCESS_TIME)
- PROCESS_TIME_ENABLED =
Qtrue
Class Method Summary collapse
-
.cpu_frequency ⇒ Object
Measurements.
- .cpu_frequency=(value) ⇒ Object
-
.exclude_threads ⇒ Object
call-seq: exclude_threads -> exclude_threads.
-
.exclude_threads=(value) ⇒ Object
call-seq: exclude_threads= -> void.
-
.figure_measure_mode ⇒ Object
Checks if the user specified the clock mode via the RUBY_PROF_MEASURE_MODE environment variable.
- .measure_allocations ⇒ Object
- .measure_cpu_time ⇒ Object
- .measure_gc_runs ⇒ Object
- .measure_gc_time ⇒ Object
- .measure_memory ⇒ Object
-
.measure_mode ⇒ Object
call-seq: measure_mode -> measure_mode.
-
.measure_mode=(value) ⇒ Object
call-seq: measure_mode=value -> void.
- .measure_process_time ⇒ Object
- .measure_wall_time ⇒ Object
- .pause ⇒ Object
-
.profile(&block) ⇒ Object
Profile a block.
- .resume ⇒ Object
- .running? ⇒ Boolean
- .start ⇒ Object
-
.start_script(script) ⇒ Object
Profiling.
- .stop ⇒ Object
Class Method Details
.cpu_frequency ⇒ Object
Measurements
6 7 8 |
# File 'lib/ruby-prof/compatibility.rb', line 6 def self.cpu_frequency Measure::CpuTime.frequency end |
.cpu_frequency=(value) ⇒ Object
10 11 12 |
# File 'lib/ruby-prof/compatibility.rb', line 10 def self.cpu_frequency=(value) Measure::CpuTime.frequency = value end |
.exclude_threads ⇒ Object
call-seq: exclude_threads -> exclude_threads
Returns threads ruby-prof should exclude from profiling
80 81 82 |
# File 'lib/ruby-prof/compatibility.rb', line 80 def self.exclude_threads @exclude_threads ||= Array.new end |
.exclude_threads=(value) ⇒ Object
call-seq: exclude_threads= -> void
Specifies what threads ruby-prof should exclude from profiling
89 90 91 |
# File 'lib/ruby-prof/compatibility.rb', line 89 def self.exclude_threads=(value) @exclude_threads = value end |
.figure_measure_mode ⇒ Object
Checks if the user specified the clock mode via the RUBY_PROF_MEASURE_MODE environment variable
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# 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 ⇒ Object
14 15 16 |
# File 'lib/ruby-prof/compatibility.rb', line 14 def self.measure_allocations Measure::Allocations.measure end |
.measure_cpu_time ⇒ Object
18 19 20 |
# File 'lib/ruby-prof/compatibility.rb', line 18 def self.measure_cpu_time Measure::CpuTime.measure end |
.measure_gc_runs ⇒ Object
22 23 24 |
# File 'lib/ruby-prof/compatibility.rb', line 22 def self.measure_gc_runs Measure::GcRuns.measure end |
.measure_gc_time ⇒ Object
26 27 28 |
# File 'lib/ruby-prof/compatibility.rb', line 26 def self.measure_gc_time Measure::GcTime.measure end |
.measure_memory ⇒ Object
30 31 32 |
# File 'lib/ruby-prof/compatibility.rb', line 30 def self.measure_memory Measure::Memory.measure end |
.measure_mode ⇒ Object
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. *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.*/
55 56 57 |
# File 'lib/ruby-prof/compatibility.rb', line 55 def self.measure_mode @measure_mode ||= RubyProf::WALL_TIME end |
.measure_mode=(value) ⇒ Object
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. *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.*/
71 72 73 |
# File 'lib/ruby-prof/compatibility.rb', line 71 def self.measure_mode=(value) @measure_mode = value end |
.measure_process_time ⇒ Object
34 35 36 |
# File 'lib/ruby-prof/compatibility.rb', line 34 def self.measure_process_time Measure::ProcessTime.measure end |
.measure_wall_time ⇒ Object
38 39 40 |
# File 'lib/ruby-prof/compatibility.rb', line 38 def self.measure_wall_time Measure::WallTime.measure end |
.pause ⇒ Object
106 107 108 109 110 |
# File 'lib/ruby-prof/compatibility.rb', line 106 def self.pause ensure_running! disable_gc_stats_if_needed @profile.pause end |
.profile(&block) ⇒ Object
Profile a block
135 136 137 138 139 140 141 |
# File 'lib/ruby-prof/compatibility.rb', line 135 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 ⇒ Object
120 121 122 123 124 |
# File 'lib/ruby-prof/compatibility.rb', line 120 def self.resume ensure_running! enable_gc_stats_if_needed @profile.resume end |
.running? ⇒ Boolean
112 113 114 115 116 117 118 |
# File 'lib/ruby-prof/compatibility.rb', line 112 def self.running? if defined?(@profile) and @profile @profile.running? else false end end |
.start ⇒ Object
99 100 101 102 103 104 |
# File 'lib/ruby-prof/compatibility.rb', line 99 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) ⇒ Object
Profiling
94 95 96 97 |
# File 'lib/ruby-prof/compatibility.rb', line 94 def self.start_script(script) start load script end |
.stop ⇒ Object
126 127 128 129 130 131 132 |
# File 'lib/ruby-prof/compatibility.rb', line 126 def self.stop ensure_running! result = @profile.stop disable_gc_stats_if_needed @profile = nil result end |