Class: PerfInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/railsbench/perf_info.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ PerfInfo

Returns a new instance of PerfInfo.



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/railsbench/perf_info.rb', line 69

def initialize(file)
  @entries = []
  file.each_line do |line|
    case line
    when /^.*perf_([a-zA-Z.]+)\s+(\d+)\s+(.*)$/
      @iterations = $2.to_i
      @options = $3
    when /\s+user\s+system\s+total\s+real/
      @entries << PerfEntry.new
    when /^(.*)\s+([\d\.]+)\s+([\d\.]+)\s+([\d\.]+)\s+\(\s*([\d\.]+)\s*\)$/
      key, time = $1.strip, $5.to_f
      if key == "loading environment"
        @entries.last.load_time = time
      else
        @entries.last.keys << key
        @entries.last.timings[key] = time
      end
    when /^GC.collections=(\d+), GC.time=([\d\.]+)$/
      @entries.last.gc_calls, @entries.last.gc_time = [$1.to_i,$2.to_f]
      @gc_stats = true
    end
  end

  @entries.each{ |e| e.total_time =  e.timings.values.sum }
  @keys = @entries.first.keys
  @runs = @entries.length
  if @keys.length == 1 && @keys[0] =~ /\((\d+) urls\)$/
    @requests_per_key = $1.to_i
  else
    @requests_per_key = 1
  end
  @request_count = @iterations * @keys.length * @requests_per_key
  @timings = PerfSummaries.inject({}){ |hash, method| hash[method] = Hash.new; hash }

  @keys.each do |k|
    a = @entries.map{|e| e.timings[k]}
    [:min, :max, :mean].each do |method|
      @timings[method][k] = a.send(method)
    end
    mean = @timings[:mean][k]
    stddev = @timings[:stddev][k] = a.send(:stddev, mean)
    @timings[:stddev_percentage][k] = stddev_percentage(stddev, mean)
  end

  PerfAttributes.each do |attr|
    next if attr.to_s =~ /^gc_/ and !gc_stats?
    a = @entries.map{|e| e.send attr}
    [:min, :max, :mean].each do |method|
      instance_variable_set "@#{attr}_#{method}", (a.send method)
    end
    mean = instance_variable_get "@#{attr}_mean"
    stddev = instance_variable_set "@#{attr}_stddev", (a.send :stddev, mean)
    instance_variable_set "@#{attr}_stddev_percentage", stddev_percentage(stddev, mean)
  end

end

Instance Attribute Details

#entriesObject (readonly)

Returns the value of attribute entries.



56
57
58
# File 'lib/railsbench/perf_info.rb', line 56

def entries
  @entries
end

#iterationsObject (readonly)

Returns the value of attribute iterations.



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

def iterations
  @iterations
end

#keysObject (readonly)

Returns the value of attribute keys.



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

def keys
  @keys
end

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

#request_countObject (readonly)

Returns the value of attribute request_count.



56
57
58
# File 'lib/railsbench/perf_info.rb', line 56

def request_count
  @request_count
end

#requests_per_keyObject (readonly)

Returns the value of attribute requests_per_key.



56
57
58
# File 'lib/railsbench/perf_info.rb', line 56

def requests_per_key
  @requests_per_key
end

#runsObject (readonly)

Returns the value of attribute runs.



56
57
58
# File 'lib/railsbench/perf_info.rb', line 56

def runs
  @runs
end

Instance Method Details

#gc_stats?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/railsbench/perf_info.rb', line 58

def gc_stats?
  @gc_stats
end