Sha256: 7ee81104d6d12f62851e34d85589bfdb782bc2938be770993b207424fe9e6c2f

Contents?: true

Size: 1.43 KB

Versions: 62

Compression:

Stored size: 1.43 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 transaction_name_or_unknown
        transaction_name || ::NewRelic::Agent::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
end

Version data entries

62 entries across 62 versions & 2 rubygems

Version Path
newrelic_rpm-5.4.0.347 lib/new_relic/agent/transaction_timings.rb
newrelic_rpm-5.3.0.346 lib/new_relic/agent/transaction_timings.rb
newrelic_rpm-5.2.0.345 lib/new_relic/agent/transaction_timings.rb
newrelic_rpm-5.1.0.344 lib/new_relic/agent/transaction_timings.rb
newrelic_rpm-5.0.0.342 lib/new_relic/agent/transaction_timings.rb
newrelic_rpm-4.8.0.341 lib/new_relic/agent/transaction_timings.rb
newrelic_rpm-4.7.1.340 lib/new_relic/agent/transaction_timings.rb
newrelic_rpm-4.7.0.339 lib/new_relic/agent/transaction_timings.rb
newrelic_rpm-4.6.0.338 lib/new_relic/agent/transaction_timings.rb
newrelic_rpm-4.5.0.337 lib/new_relic/agent/transaction_timings.rb
newrelic_rpm-4.4.0.336 lib/new_relic/agent/transaction_timings.rb
newrelic_rpm-4.3.0.335 lib/new_relic/agent/transaction_timings.rb
newrelic_rpm-4.2.0.334 lib/new_relic/agent/transaction_timings.rb
newrelic_rpm-4.1.0.333 lib/new_relic/agent/transaction_timings.rb
newrelic_rpm-4.0.0.332 lib/new_relic/agent/transaction_timings.rb
newrelic_rpm-3.18.1.330 lib/new_relic/agent/transaction_timings.rb
newrelic_rpm-3.18.0.329 lib/new_relic/agent/transaction_timings.rb
newrelic_rpm-3.17.2.327 lib/new_relic/agent/transaction_timings.rb
newrelic_rpm-3.17.1.326 lib/new_relic/agent/transaction_timings.rb
newrelic_rpm-3.17.0.325 lib/new_relic/agent/transaction_timings.rb