Class: BenchmarkForRails::ResourcePath
- Inherits:
-
Object
- Object
- BenchmarkForRails::ResourcePath
- 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
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#requests ⇒ Object
readonly
Returns the value of attribute requests.
Class Method Summary collapse
Instance Method Summary collapse
- #[](benchmark_name) ⇒ Object
- #add_request(line) ⇒ Object
- #average_time ⇒ Object
- #frequency ⇒ Object
-
#initialize(path) ⇒ ResourcePath
constructor
A new instance of ResourcePath.
- #max ⇒ Object
- #min ⇒ Object
- #total_time ⇒ Object
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
#path ⇒ Object (readonly)
Returns the value of attribute path.
84 85 86 |
# File 'lib/benchmark_for_rails/log_parser.rb', line 84 def path @path end |
#requests ⇒ Object (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_time ⇒ Object
109 110 111 |
# File 'lib/benchmark_for_rails/log_parser.rb', line 109 def average_time @average_time ||= total_time / frequency end |
#frequency ⇒ Object
101 102 103 |
# File 'lib/benchmark_for_rails/log_parser.rb', line 101 def frequency @frequency ||= requests.length end |
#max ⇒ Object
36 37 38 |
# File 'lib/benchmark_for_rails/resource_path.rb', line 36 def max @max ||= self['request'].max end |
#min ⇒ Object
32 33 34 |
# File 'lib/benchmark_for_rails/resource_path.rb', line 32 def min @min ||= self['request'].min end |
#total_time ⇒ Object
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 |