Sha256: 1df12c34c66f7378377ea6f192a044741dba7ce98bd66790bcfcef6380e6e14b

Contents?: true

Size: 1.34 KB

Versions: 215

Compression:

Stored size: 1.34 KB

Contents

require 'active_support/core_ext/module/delegation'

module ActiveSupport
  module Notifications
    class Instrumenter
      attr_reader :id

      def initialize(notifier)
        @id = unique_id
        @notifier = notifier
      end

      # Instrument the given block by measuring the time taken to execute it
      # and publish it. Notice that events get sent even if an error occurs
      # in the passed-in block
      def instrument(name, payload={})
        started = Time.now

        begin
          yield
        rescue Exception => e
          payload[:exception] = [e.class.name, e.message]
          raise e
        ensure
          @notifier.publish(name, started, Time.now, @id, payload)
        end
      end

      private
        def unique_id
          SecureRandom.hex(10)
        end
    end

    class Event
      attr_reader :name, :time, :end, :transaction_id, :payload, :duration

      def initialize(name, start, ending, transaction_id, payload)
        @name           = name
        @payload        = payload.dup
        @time           = start
        @transaction_id = transaction_id
        @end            = ending
        @duration       = 1000.0 * (@end - @time)
      end

      def parent_of?(event)
        start = (time - event.time) * 1000
        start <= 0 && (start + duration >= event.duration)
      end
    end
  end
end

Version data entries

215 entries across 171 versions & 24 rubygems

Version Path
activesupport-3.2.19 lib/active_support/notifications/instrumenter.rb
activesupport-3.2.18 lib/active_support/notifications/instrumenter.rb
activesupport-3.2.17 lib/active_support/notifications/instrumenter.rb
activesupport-3.2.16 lib/active_support/notifications/instrumenter.rb
activesupport-3.2.15 lib/active_support/notifications/instrumenter.rb
activesupport-3.2.15.rc3 lib/active_support/notifications/instrumenter.rb
activesupport-3.2.15.rc2 lib/active_support/notifications/instrumenter.rb
activesupport-3.2.15.rc1 lib/active_support/notifications/instrumenter.rb
activesupport-3.2.14 lib/active_support/notifications/instrumenter.rb
activesupport-3.2.14.rc2 lib/active_support/notifications/instrumenter.rb
activesupport-3.2.14.rc1 lib/active_support/notifications/instrumenter.rb
classiccms-0.7.2 vendor/bundle/gems/activesupport-3.2.3/lib/active_support/notifications/instrumenter.rb
classiccms-0.7.1 vendor/bundle/gems/activesupport-3.2.3/lib/active_support/notifications/instrumenter.rb
swipe-rails-0.0.5 vendor/bundle/gems/activesupport-3.2.13/lib/active_support/notifications/instrumenter.rb
active_mailer-0.0.9 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/notifications/instrumenter.rb
active_mailer-0.0.8 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/notifications/instrumenter.rb
active_mailer-0.0.7 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/notifications/instrumenter.rb
active_mailer-0.0.6 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/notifications/instrumenter.rb
classiccms-0.7.0 vendor/bundle/gems/activesupport-3.2.3/lib/active_support/notifications/instrumenter.rb
font-awesome-rails-3.1.1.2 vendor/ruby/2.0.0/gems/activesupport-3.2.12/lib/active_support/notifications/instrumenter.rb