Sha256: 66e217070422eddec6cc2b08dccd2c6d8d9d8711c0c6951f8b8c93535086aab8

Contents?: true

Size: 1.32 KB

Versions: 7

Compression:

Stored size: 1.32 KB

Contents

# encoding: utf-8
# This file is distributed under New Relic's license terms.
# See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.

module NewRelic
  module Agent
    class TransactionTimings

      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

      attr_reader :transaction_name,
        :start_time_in_seconds, :queue_time_in_seconds

      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
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
newrelic_rpm-3.7.0.174.beta lib/new_relic/agent/transaction_timings.rb
newrelic_rpm-3.6.9.171 lib/new_relic/agent/transaction_timings.rb
newrelic_rpm-3.6.8.168 lib/new_relic/agent/transaction_timings.rb
newrelic_rpm-3.6.8.164 lib/new_relic/agent/transaction_timings.rb
newrelic_rpm-3.6.7.159 lib/new_relic/agent/transaction_timings.rb
newrelic_rpm-3.6.7.159.beta lib/new_relic/agent/transaction_timings.rb
newrelic_rpm-3.6.7.152 lib/new_relic/agent/transaction_timings.rb