class Piggly::Command::Trace

This command connects to the database, dumps all stored procedures, compiles them with instrumentation code, and finally installs the instrumented code.

Public Class Methods

configure(argv, config = Config.new) click to toggle source

Parses command-line options

@return [Config]
# File lib/piggly/command/trace.rb, line 63
def configure(argv, config = Config.new)
  p = OptionParser.new do |o|
    o.on("-t", "--dry-run",           "only print the names of matching procedures", &o_dry_run(config))
    o.on("-s", "--select PATTERN",    "select procedures matching PATTERN", &o_select(config))
    o.on("-r", "--reject PATTERN",    "ignore procedures matching PATTERN", &o_reject(config))
    o.on("-c", "--cache-root PATH",   "local cache directory", &o_cache_root(config))
    o.on("-o", "--report-root PATH",  "report output directory", &o_report_root(config))
    o.on("-d", "--database PATH",     "read database adapter settings from YAML/JSON file", &o_database_yml(config))
    o.on("-k", "--connection NAME",   "use connection adapter NAME", &o_connection_name(config))
    o.on("-V", "--version",           "show version", &o_version(config))
    o.on("-h", "--help",              "show this message") { abort o.to_s }
  end

  begin
    p.parse! argv
    config
  rescue OptionParser::InvalidOption,
         OptionParser::InvalidArgument,
         OptionParser::MissingArgument
    puts p
    puts
    puts $!
    exit! 1
  end
end
dump(connection, index) click to toggle source

Writes all stored procedures in the database to disk

@return [void]
# File lib/piggly/command/trace.rb, line 38
def dump(connection, index)
  index.update(Dumper::ReifiedProcedure.all(connection))
end
install(installer, procedures, profile) click to toggle source
# File lib/piggly/command/trace.rb, line 56
def install(installer, procedures, profile)
  puts "tracing #{procedures.size} procedures"
  installer.install(procedures, profile)
end
main(argv) click to toggle source
# File lib/piggly/command/trace.rb, line 12
def main(argv)
  config     = configure(argv)
  connection = connect(config)
  index      = Dumper::Index.new(config)

  dump(connection, index)

  procedures = filter(config, index)

  if procedures.empty?
    if config.filters.empty?
      abort "no stored procedures in the cache"
    else
      abort "no stored procedures in the cache matched your criteria"
    end
  elsif config.dry_run?
    puts procedures.map{|p| p.signature }
    exit 0
  end

  trace(config, procedures)
  install(Installer.new(config, connection), procedures, Profile.new)
end
trace(config, procedures) click to toggle source

Compiles all the stored procedures on disk and installs them

@return [void]
# File lib/piggly/command/trace.rb, line 44
def trace(config, procedures)
  puts "compiling #{procedures.size} procedures"

  compiler = Compiler::TraceCompiler.new(config)
  queue    = Util::ProcessQueue.new
  procedures.each{|p| queue.add { compiler.compile(p) }}

  # Force parser to load before we start forking
  Parser.parser
  queue.execute
end