Class: Autoperf

Inherits:
Object
  • Object
show all
Defined in:
lib/autoperf.rb,
lib/autoperf/display.rb,
lib/autoperf/version.rb,
lib/autoperf/display/csv.rb,
lib/autoperf/display/json.rb,
lib/autoperf/display/console.rb

Defined Under Namespace

Classes: Display

Constant Summary collapse

VERSION =
"1.1.0"

Instance Method Summary collapse

Constructor Details

#initialize(config_file, opts = {}) ⇒ Autoperf

Returns a new instance of Autoperf.



8
9
10
11
12
13
# File 'lib/autoperf.rb', line 8

def initialize(config_file, opts = {})
  @conf       = parse_config(config_file).merge(opts)
  @perf       = HTTPerf.new(@conf, @path)
  @perf.parse = true
  @perf.tee   = true if @tee
end

Instance Method Details

#display(type = @format) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/autoperf.rb', line 42

def display(type=@format)
  @results ||= {}
  @cols    ||= nil
  case type
  when :csv
    Autoperf::Display::CSV.new(@results, @cols)
  when :json
    Autoperf::Display::JSON.new(@results, @cols)
  else
    Autoperf::Display::Console.new(@results, @cols)
  end
end

#parse_config(config_file) ⇒ Object

Raises:

  • (Errno::EACCES)


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/autoperf.rb', line 15

def parse_config(config_file)
  raise Errno::EACCES, "#{config_file} is not readable" unless File.readable?(config_file)
  config = YAML::load(File.open(config_file, 'r'))

  @rates  = {
    :low_rate  => config.delete('low_rate'),
    :high_rate => config.delete('high_rate'),
    :rate_step => config.delete('rate_step')
  }

  @cols   = config.delete('display_columns')        if config.has_key?('display_columns')
  @tee    = config.delete('tee')||false
  @format = config.delete('display_format').to_sym  if config.has_key?('display_format')
  @path   = config.delete('httperf_path')||nil

  return config
end

#run(report = nil) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/autoperf.rb', line 33

def run report=nil
  @results = {}
  (@rates[:low_rate].to_i..@rates[:high_rate].to_i).step(@rates[:rate_step].to_i) do |rate|
    @perf.update_option("rate", rate.to_s)
    @results[rate] = @perf.run
  end
  return @results
end

#to_csvObject



59
60
61
# File 'lib/autoperf.rb', line 59

def to_csv
  display(:csv).to_csv
end

#to_jsonObject



63
64
65
# File 'lib/autoperf.rb', line 63

def to_json
  display(:json).to_json
end

#to_sObject



55
56
57
# File 'lib/autoperf.rb', line 55

def to_s
  display(:console).to_s
end