class ZenProfiler

ZenProfiler provides a faster version of the standard library ruby profiler. It is otherwise pretty much the same as before.

Invoke it via:

% zenprofile misc/factorial.rb

or:

% ruby -rzenprofile misc/factorial.rb

Constants

VERSION

Public Class Methods

percent_time_threshold() click to toggle source
# File lib/zenprofiler.rb, line 41
def self.percent_time_threshold
  @@percent_time_threshold
end
percent_time_threshold=(percent_time_threshold) click to toggle source
# File lib/zenprofiler.rb, line 45
def self.percent_time_threshold=(percent_time_threshold)
  @@percent_time_threshold = percent_time_threshold
end
print_profile(f, opts = {}) click to toggle source
process(event, obj, method, klass) click to toggle source
# File lib/zenprofiler.rb, line 98
def self.process event, obj, method, klass
  case event
  when CALL, CCALL
    now = Process.times[0]
    @@stack.push [now, 0.0]
  when RETURN, CRETURN
    klass = klass.name rescue return
    key = [klass, method]
    if tick = @@stack.pop
      now = Process.times[0]
      data = @@map[key]
      data[0] += 1
      cost = now - tick[0]
      data[1] += cost
      data[2] += cost - tick[1]
      @@stack[-1][1] += cost if @@stack[-1]
    end
  end
end
run(fp = $stdout, opts = {}) click to toggle source
# File lib/zenprofiler.rb, line 28
def self.run(fp = $stdout, opts = {})
  at_exit {
    ZenProfiler::print_profile fp, opts
  }
  ZenProfiler::start_hook
end
start_hook() click to toggle source
# File lib/zenprofiler.rb, line 35
def self.start_hook
  @@start  ||= Time.now.to_f
  @@start2 ||= Process.times[0]
  super
end