Sha256: 1b219597a8780bb5ad9b5d2aff3de199c57c2891eb4154fb7ac2c26cbbe05bc9

Contents?: true

Size: 1.22 KB

Versions: 37

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::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

37 entries across 37 versions & 1 rubygems

Version Path
oneapm_rpm-1.3.6 lib/one_apm/transaction/transaction_timings.rb
oneapm_rpm-1.3.6.rc1 lib/one_apm/transaction/transaction_timings.rb
oneapm_rpm-1.3.5 lib/one_apm/transaction/transaction_timings.rb
oneapm_rpm-1.3.5.rc1 lib/one_apm/transaction/transaction_timings.rb
oneapm_rpm-1.3.4 lib/one_apm/transaction/transaction_timings.rb
oneapm_rpm-1.3.4.rc1 lib/one_apm/transaction/transaction_timings.rb
oneapm_rpm-1.3.3 lib/one_apm/transaction/transaction_timings.rb
oneapm_rpm-1.3.3.rc1 lib/one_apm/transaction/transaction_timings.rb
oneapm_rpm-1.3.2 lib/one_apm/transaction/transaction_timings.rb
oneapm_rpm-1.3.2.rc1 lib/one_apm/transaction/transaction_timings.rb
oneapm_rpm-1.3.1 lib/one_apm/transaction/transaction_timings.rb
oneapm_rpm-1.3.1.rc1 lib/one_apm/transaction/transaction_timings.rb
oneapm_rpm-1.3.0 lib/one_apm/transaction/transaction_timings.rb
oneapm_rpm-1.3.0.rc1 lib/one_apm/transaction/transaction_timings.rb
oneapm_rpm-1.2.9 lib/one_apm/transaction/transaction_timings.rb
oneapm_rpm-1.2.9.rc1 lib/one_apm/transaction/transaction_timings.rb
oneapm_rpm-1.2.8 lib/one_apm/transaction/transaction_timings.rb
oneapm_rpm-1.2.8.rc1 lib/one_apm/transaction/transaction_timings.rb
oneapm_rpm-1.2.7 lib/one_apm/transaction/transaction_timings.rb
oneapm_rpm-1.2.7.rc1 lib/one_apm/transaction/transaction_timings.rb