class ScoutApm::DbQueryMetricStats

Constants

DEFAULT_HISTOGRAM_SIZE

Attributes

call_count[R]
call_time[R]
histogram[R]
max_call_time[R]
max_rows_returned[R]
min_call_time[R]
min_rows_returned[R]
model_name[R]
operation[R]
rows_returned[R]
scope[R]
transaction_count[R]

Public Class Methods

new(model_name, operation, scope, call_count, call_time, rows_returned) click to toggle source
# File lib/scout_apm/db_query_metric_stats.rb, line 24
def initialize(model_name, operation, scope, call_count, call_time, rows_returned)
  @model_name = model_name
  @operation = operation

  @call_count = call_count

  @call_time = call_time
  @min_call_time = call_time
  @max_call_time = call_time

  @rows_returned = rows_returned
  @min_rows_returned = rows_returned
  @max_rows_returned = rows_returned

  # Should we have a histogram for timing, and one for rows_returned?
  # This histogram is for call_time
  @histogram = NumericHistogram.new(DEFAULT_HISTOGRAM_SIZE)
  @histogram.add(call_time)

  @transaction_count = 0

  @scope = scope
end

Public Instance Methods

as_json() click to toggle source
# File lib/scout_apm/db_query_metric_stats.rb, line 72
def as_json
  json_attributes = [
    :model_name,
    :operation,
    :scope,

    :transaction_count,
    :call_count,

    :histogram,
    :call_time,
    :max_call_time,
    :min_call_time,

    :max_rows_returned,
    :min_rows_returned,
    :rows_returned,
  ]

  ScoutApm::AttributeArranger.call(self, json_attributes)
end
combine!(other) click to toggle source

Combine data from another DbQueryMetricStats into self. Modifies and returns self

# File lib/scout_apm/db_query_metric_stats.rb, line 54
def combine!(other)
  return self if other == self

  @transaction_count += other.transaction_count
  @call_count += other.call_count
  @rows_returned += other.rows_returned
  @call_time += other.call_time

  @min_call_time = other.min_call_time if @min_call_time.zero? or other.min_call_time < @min_call_time
  @max_call_time = other.max_call_time if other.max_call_time > @max_call_time

  @min_rows_returned = other.min_rows_returned if @min_rows_returned.zero? or other.min_rows_returned < @min_rows_returned
  @max_rows_returned = other.max_rows_returned if other.max_rows_returned > @max_rows_returned

  @histogram.combine!(other.histogram)
  self
end
increment_transaction_count!() click to toggle source

Called by the Set on each DbQueryMetricStats object that it holds, only once during the recording of a transaction.

Don't call elsewhere, and don't set to 1 in the initializer.

# File lib/scout_apm/db_query_metric_stats.rb, line 98
def increment_transaction_count!
  @transaction_count += 1
end
key() click to toggle source

Merge data in this scope. Used in DbQueryMetricSet

# File lib/scout_apm/db_query_metric_stats.rb, line 49
def key
  @key ||= [model_name, operation, scope]
end