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-3.16.3.323 lib/new_relic/agent/transaction_timings.rb
newrelic_rpm-3.16.2.321 lib/new_relic/agent/transaction_timings.rb
newrelic_rpm-3.16.1.320 lib/new_relic/agent/transaction_timings.rb
newrelic_rpm-3.16.0.318 lib/new_relic/agent/transaction_timings.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/newrelic_rpm-3.15.2.317/lib/new_relic/agent/transaction_timings.rb
newrelic_rpm-3.15.2.317 lib/new_relic/agent/transaction_timings.rb
newrelic_rpm-3.15.1.316 lib/new_relic/agent/transaction_timings.rb
newrelic_rpm-3.15.0.314 lib/new_relic/agent/transaction_timings.rb
newrelic_rpm-3.14.3.313 lib/new_relic/agent/transaction_timings.rb
newrelic_rpm-3.14.2.312 lib/new_relic/agent/transaction_timings.rb
newrelic_rpm-3.14.1.311 lib/new_relic/agent/transaction_timings.rb
newrelic_rpm-3.14.0.305 lib/new_relic/agent/transaction_timings.rb
newrelic_rpm-3.13.2.302 lib/new_relic/agent/transaction_timings.rb
newrelic_rpm-3.13.1.300 lib/new_relic/agent/transaction_timings.rb
newrelic_rpm-3.13.0.299 lib/new_relic/agent/transaction_timings.rb
newrelic_rpm-3.12.1.298 lib/new_relic/agent/transaction_timings.rb
newrelic_rpm-3.12.0.288 lib/new_relic/agent/transaction_timings.rb
newrelic_rpm-3.11.2.286 lib/new_relic/agent/transaction_timings.rb
newrelic_rpm-3.11.1.284 lib/new_relic/agent/transaction_timings.rb
newrelic_rpm-3.11.0.283 lib/new_relic/agent/transaction_timings.rb