class Lineprof

Constants

DEFAULT_PATTERN
IGNORE_PATTERN
VERSION

Public Class Methods

profile(filename = caller_filename(caller), &block) click to toggle source
# File lib/lineprof.rb, line 9
def profile(filename = caller_filename(caller), &block)
  value  = nil
  result = lineprof(filename) { value = block.call }

  puts Term::ANSIColor.blue("\n[Lineprof] #{'=' * 70}")
  puts "\n#{format(result)}\n"
  value
end

Private Class Methods

caller_filename(caller_lines) click to toggle source
# File lib/lineprof.rb, line 20
def caller_filename(caller_lines)
  filename = caller_lines.first.split(':').first

  if filename
    # Don't add \A because filename may not be an absolute path
    /#{Regexp.escape(filename)}\z/
  else
    DEFAULT_PATTERN
  end
end
format(result) click to toggle source
# File lib/lineprof.rb, line 31
def format(result)
  sources = result.map do |filename, samples|
    next if filename =~ IGNORE_PATTERN
    Rack::Lineprof::Source.new(filename, samples)
  end
  sources.compact.map(&:format).join("\n")
end