Class: BenchmarkForRails::ResourcePath

Inherits:
Object
  • Object
show all
Defined in:
lib/benchmark_for_rails/log_parser.rb,
lib/benchmark_for_rails/resource_path.rb

Constant Summary collapse

PATH_STRIP_RE =

pre-generate the regular expressions. this matters when you loop one million times.

/.*\] */
MEASUREMENT_SPLIT_RE =
/ *: */
PATH_RE =
/\[(.*?)\]/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ ResourcePath

Returns a new instance of ResourcePath.



87
88
89
90
# File 'lib/benchmark_for_rails/log_parser.rb', line 87

def initialize(path)
  @path = path
  @requests = []
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



84
85
86
# File 'lib/benchmark_for_rails/log_parser.rb', line 84

def path
  @path
end

#requestsObject (readonly)

Returns the value of attribute requests.



85
86
87
# File 'lib/benchmark_for_rails/log_parser.rb', line 85

def requests
  @requests
end

Class Method Details

.path_from(str) ⇒ Object



113
114
115
# File 'lib/benchmark_for_rails/log_parser.rb', line 113

def self.path_from(str)
  PATH_RE.match(str)[1]
end

Instance Method Details

#[](benchmark_name) ⇒ Object



44
45
46
# File 'lib/benchmark_for_rails/resource_path.rb', line 44

def [](benchmark_name)
  requests.collect{|r| r[benchmark_name.to_s]}
end

#add_request(line) ⇒ Object



92
93
94
95
96
97
98
99
# File 'lib/benchmark_for_rails/log_parser.rb', line 92

def add_request(line)
  measurements = {}
  line.sub(PATH_STRIP_RE, '').split(' | ').each do |measurement|
    md = MEASUREMENT_SPLIT_RE.match(measurement)
    measurements[md.pre_match] = md.post_match.to_f
  end
  self.requests << measurements
end

#average_timeObject



109
110
111
# File 'lib/benchmark_for_rails/log_parser.rb', line 109

def average_time
  @average_time ||= total_time / frequency
end

#frequencyObject



101
102
103
# File 'lib/benchmark_for_rails/log_parser.rb', line 101

def frequency
  @frequency ||= requests.length
end

#maxObject



36
37
38
# File 'lib/benchmark_for_rails/resource_path.rb', line 36

def max
  @max ||= self['request'].max
end

#minObject



32
33
34
# File 'lib/benchmark_for_rails/resource_path.rb', line 32

def min
  @min ||= self['request'].min
end

#total_timeObject



105
106
107
# File 'lib/benchmark_for_rails/log_parser.rb', line 105

def total_time
  @total_time ||= requests.collect{|r| r['request']}.sum
end