Class: Lutaml::Model::PerformanceStats

Inherits:
Object
  • Object
show all
Defined in:
lib/lutaml/model/instrumentation.rb

Overview

Performance statistics collector

Collects and aggregates performance metrics across operations

Examples:

stats = Lutaml::Model::PerformanceStats.new
stats.record(:parse, 12.5)
stats.record(:parse, 15.2)
stats.average(:parse) #=> 13.85

Instance Method Summary collapse

Constructor Details

#initializePerformanceStats

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

Parameters:

  • name (Symbol)

    the metric name

Returns:

  • (Float, nil)


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

#clearvoid

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

Parameters:

  • name (Symbol)

    the metric name

Returns:

  • (Integer)


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

Parameters:

  • name (Symbol)

    the metric name

Returns:

  • (Numeric, nil)


260
261
262
# File 'lib/lutaml/model/instrumentation.rb', line 260

def max(name)
  @metrics[name].max
end

#metric_namesArray<Symbol>

Get all metric names

Returns:

  • (Array<Symbol>)


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

Parameters:

  • name (Symbol)

    the metric name

Returns:

  • (Numeric, nil)


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

Parameters:

  • name (Symbol)

    the metric name

  • value (Numeric)

    the value to record



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

Parameters:

  • name (Symbol)

    the metric name

Returns:



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

Parameters:

  • name (Symbol)

    the metric name

Returns:

  • (Array<Numeric>)


233
234
235
# File 'lib/lutaml/model/instrumentation.rb', line 233

def values(name)
  @metrics[name].dup
end