lib/speed_gun/profiler.rb in speed_gun-1.0.0.rc1 vs lib/speed_gun/profiler.rb in speed_gun-2.0.0.pre.alpha.1
- old
+ new
@@ -1,21 +1,27 @@
+# frozen_string_literal: true
require 'speed_gun'
+require 'speed_gun/event'
-# @abstract
class SpeedGun::Profiler
def self.profile(*args, &block)
new.profile(*args, &block)
end
- def profile(name = self.class.name, payload = {}, &block)
- starts_at = Time.now
+ def self.ignore?
+ SpeedGun.config.ignored_profilers.any? do |ignore|
+ name.include?(ignore)
+ end
+ end
- ret = yield
+ def profile(name = self.class.name, payload = {})
+ started_at = Time.now
- event = SpeedGun::Event.new(
- name, payload, starts_at, Time.now
- )
- SpeedGun.current_profile.record!(event)
+ event = SpeedGun::Event.new(name, payload, started_at)
+ result = yield(event)
+ event.finish!
- return ret
+ SpeedGun.record(event) unless self.class.ignore?
+
+ result
end
end