Module: RubyProf

Extended by:
Gem::Deprecate
Defined in:
lib/ruby-prof/compatibility.rb,
lib/ruby-prof.rb,
lib/ruby-prof/task.rb,
lib/ruby-prof/thread.rb,
lib/ruby-prof/profile.rb,
lib/ruby-prof/version.rb,
lib/ruby-prof/call_tree.rb,
lib/ruby-prof/measurement.rb,
lib/ruby-prof/method_info.rb,
lib/ruby-prof/call_tree_visitor.rb,
lib/ruby-prof/printers/dot_printer.rb,
lib/ruby-prof/printers/flat_printer.rb,
lib/ruby-prof/exclude_common_methods.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,
ext/ruby_prof/ruby_prof.c

Overview

:enddoc:

Defined Under Namespace

Modules: ExcludeCommonMethods, Measure Classes: AbstractPrinter, Allocation, CallInfoPrinter, CallStackPrinter, CallTree, CallTreePrinter, CallTreeVisitor, CallTrees, DotPrinter, FlatPrinter, GraphHtmlPrinter, GraphPrinter, Measurement, MethodInfo, MultiPrinter, Profile, ProfileTask, Thread

Constant Summary collapse

VERSION =
"1.7.1"
MEMORY =
INT2NUM(MEASURE_MEMORY)
WALL_TIME =
INT2NUM(MEASURE_WALL_TIME)
ALLOCATIONS =
INT2NUM(MEASURE_ALLOCATIONS)
CLOCKS_PER_SEC =
INT2NUM(CLOCKS_PER_SEC)
PROCESS_TIME =
INT2NUM(MEASURE_PROCESS_TIME)

Class Method Summary collapse

Class Method Details

.exclude_threadsObject

Returns the threads that ruby-prof should exclude from profiling



32
33
34
# File 'lib/ruby-prof/compatibility.rb', line 32

def self.exclude_threads
  @exclude_threads ||= Array.new
end

.exclude_threads=(value) ⇒ Object

Specifies which threads ruby-prof should exclude from profiling



37
38
39
# File 'lib/ruby-prof/compatibility.rb', line 37

def self.exclude_threads=(value)
  @exclude_threads = value
end

.figure_measure_modeObject

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



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# 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 "allocations"
    RubyProf.measure_mode = RubyProf::ALLOCATIONS
  when "memory"
    RubyProf.measure_mode = RubyProf::MEMORY
  when "process", "process_time"
    RubyProf.measure_mode = RubyProf::PROCESS_TIME
  else
    # the default is defined in the measure_mode reader
  end
end

.measure_modeObject

call-seq: measure_mode -> measure_mode

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

  • RubyProf::WALL_TIME

  • RubyProf::PROCESS_TIME

  • RubyProf::ALLOCATIONS

  • RubyProf::MEMORY



14
15
16
# File 'lib/ruby-prof/compatibility.rb', line 14

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::WALL_TIME - Wall time measures the real-world time elapsed between any two moments. If there are other processes concurrently running on the system that use significant CPU or disk time during a profiling run then the reported results will be larger than expected. On Windows, wall time is measured using GetTickCount(), on MacOS by mach_absolute_time, on Linux by clock_gettime and otherwise by gettimeofday.

  • RubyProf::PROCESS_TIME - Process time measures the time used by a process between any two moments. It is unaffected by other processes concurrently running on the system. Remember with process time that calls to methods like sleep will not be included in profiling results. On Windows, process time is measured using GetProcessTimes and on other platforms by clock_gettime.

  • RubyProf::ALLOCATIONS - Object allocations measures show how many objects each method in a program allocates. Measurements are done via Ruby’s GC.stat api.

  • RubyProf::MEMORY - Memory measures how much memory each method in a program uses. Measurements are done via Ruby’s TracePoint api.



27
28
29
# File 'lib/ruby-prof/compatibility.rb', line 27

def self.measure_mode=(value)
  @measure_mode = value
end

.pauseObject

Pauses profiling



49
50
51
52
# File 'lib/ruby-prof/compatibility.rb', line 49

def self.pause
  ensure_running!
  @profile.pause
end

.profile(options = {}, &block) ⇒ Object

Profiles a block



78
79
80
81
82
# File 'lib/ruby-prof/compatibility.rb', line 78

def self.profile(options = {}, &block)
  ensure_not_running!
  options = {:measure_mode => measure_mode, :exclude_threads => exclude_threads }.merge!(options)
  Profile.profile(options, &block)
end

.resumeObject

Resume profiling



64
65
66
67
# File 'lib/ruby-prof/compatibility.rb', line 64

def self.resume
  ensure_running!
  @profile.resume
end

.running?Boolean

Is a profile running?

Returns:

  • (Boolean)


55
56
57
58
59
60
61
# File 'lib/ruby-prof/compatibility.rb', line 55

def self.running?
  if defined?(@profile) and @profile
    @profile.running?
  else
    false
  end
end

.startObject

Starts profiling



42
43
44
45
46
# File 'lib/ruby-prof/compatibility.rb', line 42

def self.start
  ensure_not_running!
  @profile = Profile.new(:measure_mode => measure_mode, :exclude_threads => exclude_threads)
  @profile.start
end

.start_script(script) ⇒ Object

:nodoc:



85
86
87
88
# File 'lib/ruby-prof/compatibility.rb', line 85

def self.start_script(script)
  start
  load script
end

.stopObject

Stops profiling



70
71
72
73
74
75
# File 'lib/ruby-prof/compatibility.rb', line 70

def self.stop
  ensure_running!
  result = @profile.stop
  @profile = nil
  result
end