class Staccato::Subscribers::Timing

Public Class Methods

call(*args) click to toggle source
# File lib/staccato/subscribers/timing.rb, line 4
def self.call(*args)
  new(args).track!
end
new(args) click to toggle source
# File lib/staccato/subscribers/timing.rb, line 8
def initialize(args)
  @args = args
end

Public Instance Methods

db_runtime() click to toggle source
# File lib/staccato/subscribers/timing.rb, line 16
def db_runtime
  @db_runtime ||= payload[:db_runtime]
end
times() click to toggle source
# File lib/staccato/subscribers/timing.rb, line 24
def times
  [
    {label: :total, time: total_runtime},
    {label: :db, time: db_runtime},
    {label: :view, time: view_runtime}
  ]
end
total_runtime() click to toggle source
# File lib/staccato/subscribers/timing.rb, line 12
def total_runtime
  @total_runtime ||= event.duration
end
track!() click to toggle source
# File lib/staccato/subscribers/timing.rb, line 32
def track!
  params = context.merge(category: :rails, variable: :runtime)

  times.each do |time|
    tracker.timing(params.merge(time))
  end
end
view_runtime() click to toggle source
# File lib/staccato/subscribers/timing.rb, line 20
def view_runtime
  @view_runtime ||= payload[:view_runtime]
end

Private Instance Methods

context() click to toggle source
# File lib/staccato/subscribers/timing.rb, line 53
def context
  @context ||= payload['staccato.context']
end
event() click to toggle source
# File lib/staccato/subscribers/timing.rb, line 41
def event
  @event ||= ActiveSupport::Notifications::Event.new(*@args)
end
payload() click to toggle source
# File lib/staccato/subscribers/timing.rb, line 45
def payload
  @payload ||= event.payload
end
tracker() click to toggle source
# File lib/staccato/subscribers/timing.rb, line 49
def tracker
  @tracker ||= payload['staccato.tracker']
end