Sha256: dffaa57b17f89a20f005b5c2136f38035f8ec8d5d419f1ef2caa096395c33a4a

Contents?: true

Size: 1.22 KB

Versions: 5

Compression:

Stored size: 1.22 KB

Contents

# encoding: utf-8

module OneApm
  class TransactionTimings

    attr_reader :transaction_name,
                :start_time_in_seconds,
                :queue_time_in_seconds

    def initialize(queue_time_in_seconds, start_time_in_seconds, transaction_name)
      @now = Time.now.to_f
      @queue_time_in_seconds = clamp_to_positive(queue_time_in_seconds.to_f)
      @start_time_in_seconds = clamp_to_positive(start_time_in_seconds.to_f)

      @transaction_name = transaction_name
    end

    def transaction_name_or_unknown
      transaction_name || OneApm::Transaction::OA_UNKNOWN_METRIC
    end

    def start_time_as_time
      Time.at(@start_time_in_seconds)
    end

    def start_time_in_millis
      convert_to_milliseconds(@start_time_in_seconds)
    end

    def queue_time_in_millis
      convert_to_milliseconds(queue_time_in_seconds)
    end

    def app_time_in_millis
      convert_to_milliseconds(app_time_in_seconds)
    end

    def app_time_in_seconds
      @now - @start_time_in_seconds
    end

    # Helpers

    def convert_to_milliseconds(value_in_seconds)
      clamp_to_positive((value_in_seconds.to_f * 1000.0).round)
    end

    def clamp_to_positive(value)
      return 0.0 if value < 0.0
      value
    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
oneapm_rpm-1.4.2 lib/one_apm/transaction/transaction_timings.rb
oneapm_rpm-1.4.1 lib/one_apm/transaction/transaction_timings.rb
oneapm_rpm-1.4.0 lib/one_apm/transaction/transaction_timings.rb
oneapm_rpm-1.3.7 lib/one_apm/transaction/transaction_timings.rb
oneapm_rpm-1.3.7.rc1 lib/one_apm/transaction/transaction_timings.rb