Class: Lutaml::Model::PerformanceStats
- Inherits:
-
Object
- Object
- Lutaml::Model::PerformanceStats
- Defined in:
- lib/lutaml/model/instrumentation.rb
Overview
Performance statistics collector
Collects and aggregates performance metrics across operations
Instance Method Summary collapse
-
#average(name) ⇒ Float?
Calculate average for a metric.
-
#clear ⇒ void
Clear all recorded metrics.
-
#count(name) ⇒ Integer
Get count of recordings for a metric.
-
#initialize ⇒ PerformanceStats
constructor
A new instance of PerformanceStats.
-
#max(name) ⇒ Numeric?
Get maximum value for a metric.
-
#metric_names ⇒ Array<Symbol>
Get all metric names.
-
#min(name) ⇒ Numeric?
Get minimum value for a metric.
-
#record(name, value) ⇒ void
Record a metric value.
-
#summary(name) ⇒ Hash
Get summary statistics for a metric.
-
#values(name) ⇒ Array<Numeric>
Get all recorded values for a metric.
Constructor Details
#initialize ⇒ PerformanceStats
Returns a new instance of PerformanceStats.
216 217 218 |
# File 'lib/lutaml/model/instrumentation.rb', line 216 def initialize @metrics = Hash.new { |h, k| h[k] = [] } end |
Instance Method Details
#average(name) ⇒ Float?
Calculate average for a metric
241 242 243 244 245 246 |
# File 'lib/lutaml/model/instrumentation.rb', line 241 def average(name) vals = @metrics[name] return nil if vals.empty? vals.sum / vals.size.to_f end |
#clear ⇒ void
This method returns an undefined value.
Clear all recorded metrics
299 300 301 |
# File 'lib/lutaml/model/instrumentation.rb', line 299 def clear @metrics.clear end |
#count(name) ⇒ Integer
Get count of recordings for a metric
268 269 270 |
# File 'lib/lutaml/model/instrumentation.rb', line 268 def count(name) @metrics[name].size end |
#max(name) ⇒ Numeric?
Get maximum value for a metric
260 261 262 |
# File 'lib/lutaml/model/instrumentation.rb', line 260 def max(name) @metrics[name].max end |
#metric_names ⇒ Array<Symbol>
Get all metric names
292 293 294 |
# File 'lib/lutaml/model/instrumentation.rb', line 292 def metric_names @metrics.keys end |
#min(name) ⇒ Numeric?
Get minimum value for a metric
252 253 254 |
# File 'lib/lutaml/model/instrumentation.rb', line 252 def min(name) @metrics[name].min end |
#record(name, value) ⇒ void
This method returns an undefined value.
Record a metric value
225 226 227 |
# File 'lib/lutaml/model/instrumentation.rb', line 225 def record(name, value) @metrics[name] << value end |
#summary(name) ⇒ Hash
Get summary statistics for a metric
276 277 278 279 280 281 282 283 284 285 286 287 |
# File 'lib/lutaml/model/instrumentation.rb', line 276 def summary(name) vals = @metrics[name] return {} if vals.empty? { count: vals.size, min: vals.min, max: vals.max, average: (vals.sum / vals.size.to_f).round(2), total: vals.sum.round(2), } end |
#values(name) ⇒ Array<Numeric>
Get all recorded values for a metric
233 234 235 |
# File 'lib/lutaml/model/instrumentation.rb', line 233 def values(name) @metrics[name].dup end |