Sha256: 9572a5652142ddc56526310adefd5ec0276b0f7f3d5fca34e875cb2d5f30e6aa

Contents?: true

Size: 758 Bytes

Versions: 1

Compression:

Stored size: 758 Bytes

Contents

require 'speed_gun/profiler'

class SpeedGun::Profiler::ActiveSupportNotificatiosProfiler < SpeedGun::Profiler
  def self.subscribe(event, ignore_payload = [])
    klass = self
    ActiveSupport::Notifications.subscribe(event) do |*args|
      klass.record(event, *args, ignore_payload)
    end
  end

  def self.record(event, name, started, ended, id, payload, ignore_payload)
    name = "#{self.name}.#{name.sub(event, '\1')}"

    payload.symbolize_keys!

    ignore_payload.each do |key|
      payload.delete(key)
    end

    payload[:backtrace] = backtrace

    event = SpeedGun::Event.new(name, payload, started, ended)
    SpeedGun.current_profile.record!(event)
  end

  def self.backtrace
    Rails.backtrace_cleaner.clean(caller[2..-1])
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
speed_gun-1.0.0.rc1 lib/speed_gun/profiler/active_support_notifications_profiler.rb