Sha256: 601407c0b9c1e7c9931dd6d32d5e84530f20ea7dd087f14afcc039f81352018f

Contents?: true

Size: 549 Bytes

Versions: 1

Compression:

Stored size: 549 Bytes

Contents

# frozen_string_literal: true
require 'speed_gun'
require 'speed_gun/event'

class SpeedGun::Profiler
  def self.profile(*args, &block)
    new.profile(*args, &block)
  end

  def self.ignore?
    SpeedGun.config.ignored_profilers.any? do |ignore|
      name.include?(ignore)
    end
  end

  def profile(name = self.class.name, payload = {})
    started_at = Time.now

    event = SpeedGun::Event.new(name, payload, started_at)
    result = yield(event)
    event.finish!

    SpeedGun.record(event) unless self.class.ignore?

    result
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
speed_gun-2.0.0.pre.alpha.1 lib/speed_gun/profiler.rb