require 'optparse' require 'drb/drb' module Fluent class Stackprof def parse_options(argv = ARGV) op = OptionParser.new op.banner += ' [output_file]' (class< e usage e.message end unless opts[:unix].nil? uri = "drbunix:#{opts[:unix]}" else uri = "druby://#{opts[:host]}:#{opts[:port]}" end $remote_engine = DRb::DRbObject.new_with_uri(uri) case opts[:command] when 'start' remote_code = <<-CODE require 'stackprof' StackProf.start(mode: :#{opts[:mode]}) CODE when 'stop' remote_code = <<-"CODE" StackProf.stop StackProf.results('#{opts[:output]}') CODE end puts remote_code $remote_engine.method_missing(:instance_eval, remote_code) case opts[:command] when 'start' $stdout.puts 'fluent-stackprof: started' when 'stop' $stdout.puts "fluent-stackprof: outputs to #{opts[:output]}" end end end end