module Lingo::Debug

Constants

PS_COLUMNS
PS_COMMAND
PS_NO_HEADING
PS_RE

Public Instance Methods

profile(base) { || ... } click to toggle source
# File lib/lingo/debug.rb, line 46
def profile(base)
  return yield unless base

  require 'ruby-prof'

  result = RubyProf.profile { yield }
  result.eliminate_methods! [/\b(?:Gem|HighLine)\b/,
    /\A(?:Benchmark|FileUtils|Pathname|Util)\b/]

  if base.is_a?(IO)
    RubyProf::FlatPrinter.new(result).print(base)
  else
    FileUtils.mkdir_p(File.dirname(base))

    mode = ENV['RUBY_PROF_MEASURE_MODE']
    base += "-#{mode}" if mode && !mode.empty?

    {
      txt:   :FlatPrinter,
      lines: :FlatPrinterWithLineNumbers,
      html:  :GraphHtmlPrinter,
      stack: :CallStackPrinter
    }.each { |ext, name|
      File.open("#{base}.#{ext}", 'a+', encoding: ENCODING) { |f|
        RubyProf.const_get(name).new(result).print(f)
      }
    }
  end
end
ps(name) click to toggle source
# File lib/lingo/debug.rb, line 39
def ps(name)
  system(PS_COMMAND,
    '-o', PS_COLUMNS,
    "--#{'no-' if PS_NO_HEADING[name]}heading",
    Process.pid.to_s) if name =~ PS_RE
end