lib/stella/adapter/siege.rb in stella-0.5.4 vs lib/stella/adapter/siege.rb in stella-0.5.5

- old
+ new

@@ -36,19 +36,21 @@ attr_reader :user_agent attr_accessor :help, :config, :verbose, :get, :log, :mark, :delay, :header attr_accessor :rc, :file, :time, :benchmark, :internet def initialize(options={}, arguments=[]) - super(options, arguments) + @name = 'siege' @reps = 1 @concurrent = 1 @private_variables = ['private_variables', 'name', 'arguments', 'load_factor', 'working_directory', 'orig_logfile'] @load_factor = 1 @rc = File.join(ENV['HOME'] || ENV['USERPROFILE'], '.siegerc') + super(options, arguments) + # Siege won't run unless there's a siegerc file. If the default one doesn't exist # we need to call siege.config to create it. This should only happen once. # We use capture_output here so STDOUT and STDERR don't print to the screen. Stella::Util.capture_output("#{@name}.config") do 'nothing' end unless File.exists? @rc end @@ -119,16 +121,14 @@ # After calling run def after update_orig_logfile if @orig_logfile - save_stats end - def process_options(arguments) - options = OpenStruct.new + def process_arguments(arguments) opts = OptionParser.new opts.on('-V', '--version') do |v| @version = v end opts.on('-h', '--help') do |v| @help = v end opts.on('-C', '--config') do |v| @config = v end opts.on('-v', '--verbose') do |v| @verbose = v end @@ -145,24 +145,27 @@ opts.on('-t S', '--time=S', String) do |v| @time = v end opts.on('-b', '--benchmark') do |v| @benchmark = true; end opts.on('-i', '--internet') do |v| @internet = true; end opts.on('-A S', '--user-agent=S', String) do |v| @user_agent ||= []; @user_agent << v end - unless options.benchmark - Stella::LOGGER.warn('--benchmark (or -b) is not selected. Siege will include "think-time" for all requests.') - end opts.on('-n N',Integer) do |v| Stella::LOGGER.error("-n is not a Siege parameter. You probably want -r.") exit 1 end # parse! removes the options it finds. # It also fails when it finds unknown switches (i.e. -X) # Which should leave only the remaining arguments (URIs in this case) opts.parse!(arguments) - options + + unless @benchmark + Stella::LOGGER.warn('--benchmark (or -b) is not selected. Siege will include "think time" for all requests.') + end + + self.arguments = arguments + rescue OptionParser::InvalidOption => ex # We want to replace this text so we grab just the name of the argument badarg = ex.message.gsub('invalid option: ', '') raise InvalidArgument.new(badarg) end @@ -271,11 +274,11 @@ @file = uris_file end end # Siege writes the summary to STDERR - def stats_file + def summary_file File.new(stderr_path) if File.exists?(stderr_path) end def rc_file File.join(@working_directory, "siegerc") @@ -287,13 +290,13 @@ def uris_file File.join(@working_directory, File.basename(@file)) end - def stats - return unless stats_file + def summary + return unless summary_file raw = {} - stats_file.each_line { |l| + summary_file.each_line { |l| l.chomp! nvpair = l.split(':') next unless nvpair && nvpair.size == 2 n = nvpair[0].strip.tr(' ', '_').downcase[/\w+/] v = nvpair[1].strip[/[\.\d]+/] \ No newline at end of file